lots of work on determinism in the linux driver.

This commit is contained in:
2022-02-18 03:59:21 -05:00
parent 6a6d2c7f75
commit ba1e923b5a
10 changed files with 175 additions and 110 deletions

View File

@@ -19,38 +19,6 @@ static void dump_lines(StreamBuffer *in, StreamBuffer *out, int chid) {
}
}
// This test allows input on stdin or on port 8085.
// You can type lines and see them echoed.
class DriverListenTest : public DrivenEngine {
public:
std::vector<SharedChannel> channels_;
virtual void event_init(int argc, char *argv[]) {
listen_port(8085);
}
virtual void event_update() {
while (true) {
SharedChannel ch = new_incoming_channel();
if (ch == nullptr) break;
ch->set_readline(true);
channels_.emplace_back(std::move(ch));
}
SharedChannel stdioch = get_stdio_channel();
dump_lines(stdioch->in(), stdioch->out(), 0);
std::vector<SharedChannel> keep;
for (SharedChannel &ch : channels_) {
dump_lines(ch->in(), stdioch->out(), ch->chid());
if (ch->closed()) {
write_closed_message(ch.get(), stdioch->out());
} else {
keep.emplace_back(std::move(ch));
}
}
channels_ = std::move(keep);
}
};
// This test connects to a public webserver and prints
// the output from the server.
class DriverWebServerTest : public DrivenEngine {
@@ -104,6 +72,15 @@ public:
}
};
static int64_t mallocstate() {
int64_t result = 0;
for (int i = 0; i < 10; i++) {
int64_t n = int64_t(malloc(1));
result = (result * 17) + n;
}
return result;
}
// This test just prints the time.
class DriverPrintClockTest : public DrivenEngine {
public:
@@ -117,11 +94,12 @@ public:
virtual void event_update() {
double clock = get_clock();
if (clock > last_clock_ + 0.5) {
stdostream() << std::fixed << std::setprecision(2) << clock << " ";
int64_t ms = mallocstate();
stdostream() << std::fixed << std::setprecision(2) << clock << " " << std::hex << ms << " ";
count_++;
last_clock_ = clock;
}
if (count_ == 10) {
if (count_ == 4) {
stdostream() << std::endl;
count_ = 0;
}
@@ -143,10 +121,6 @@ private:
};
UniqueDrivenEngine make_DriverListenTest() {
return UniqueDrivenEngine(new DriverListenTest);
}
UniqueDrivenEngine make_DriverWebServerTest() {
return UniqueDrivenEngine(new DriverWebServerTest);
}