diff --git a/build_coverage.sh b/build_coverage.sh index 7be4ce3..e7097ed 100644 --- a/build_coverage.sh +++ b/build_coverage.sh @@ -9,7 +9,7 @@ echo "=== Step 1: Building simulation with coverage instrumentation ===" gcc src/sha256.c src/basic.c src/file_system.c src/byte_queue.c src/file_tree.c \ src/message.c src/tcp.c src/wal.c src/hash_set.c src/client.c \ src/metadata_server.c src/chunk_server.c src/random_client.c src/main.c \ - quakey/src/lfs.c quakey/src/lfs_util.c quakey/src/quakey.c \ + quakey/src/mockfs.c quakey/src/quakey.c \ -o "$SIMULATION_BINARY" \ -Iquakey/include -Iinclude \ -Wall -Wextra -ggdb -O0 \ diff --git a/quakey/include/quakey.h b/quakey/include/quakey.h index 17f46b2..3bdfa70 100644 --- a/quakey/include/quakey.h +++ b/quakey/include/quakey.h @@ -40,6 +40,10 @@ typedef enum { typedef struct { + // Label associated to the process for debugging + // The string must have global lifetime + char *name; + // Size of the opaque state struct int state_size; diff --git a/quakey/src/quakey.c b/quakey/src/quakey.c index feda76c..29eb06b 100644 --- a/quakey/src/quakey.c +++ b/quakey/src/quakey.c @@ -235,6 +235,8 @@ struct Host { // Pointer to the parent simulation object Sim *sim; + char *name; + // Platform used by this host QuakeyPlatform platform; @@ -275,6 +277,7 @@ struct Host { int poll_timeout; b32 timedout; + b32 blocked; // Current error number set by system call mocks int errno_; @@ -886,6 +889,7 @@ static int split_args(char *arg, char **argv, int max_argc) static void host_init(Host *host, Sim *sim, QuakeySpawn config, char *arg) { host->sim = sim; + host->name = config.name; host->platform = config.platform; host->next_ephemeral_port = FIRST_EPHEMERAL_PORT; @@ -943,6 +947,7 @@ static void host_init(Host *host, Sim *sim, QuakeySpawn config, char *arg) } host->timedout = false; + host->blocked = false; host->poll_count = 0; host->poll_timeout = -1; @@ -1019,6 +1024,9 @@ static bool is_desc_idx_valid(Host *host, int desc_idx); static bool host_ready(Host *host) { + if (host->blocked) + return false; + if (host->timedout) return true; @@ -2170,15 +2178,20 @@ static b32 sim_update(Sim *sim) if (host_idx > -1) break; - if (sim->num_events == 0) - __builtin_trap(); // TODO: remove me + for (int i = 0; i < sim->num_hosts; i++) + sim->hosts[i]->blocked = false; advance_time_to_next_event(sim); process_events_at_current_time(sim); } move_host_to_last(sim, host_idx); - host_update(sim->hosts[sim->num_hosts-1]); + + Host *host = sim->hosts[sim->num_hosts-1]; + host_update(host); + if (host_ready(host)) + host->blocked = true; + return true; } diff --git a/src/client.c b/src/client.c index b5a0548..262db6a 100644 --- a/src/client.c +++ b/src/client.c @@ -36,7 +36,8 @@ typedef pthread_mutex_t Mutex; #define PARALLEL_LIMIT 5 -#define CLIENT_TRACE(fmt, ...) fprintf(stderr, "CLIENT: " fmt "\n", ##__VA_ARGS__); +#define CLIENT_TRACE(fmt, ...) {} +//#define CLIENT_TRACE(fmt, ...) fprintf(stderr, "CLIENT: " fmt "\n", ##__VA_ARGS__); typedef struct { SHA256 hash; diff --git a/src/main.c b/src/main.c index 50c7ca8..65a92c9 100644 --- a/src/main.c +++ b/src/main.c @@ -131,6 +131,7 @@ int main(void) // Client { QuakeySpawn config = { + .name = "client", .state_size = sizeof(RandomClient), .init_func = random_client_init, .tick_func = random_client_tick, @@ -146,6 +147,7 @@ int main(void) // Metadata Server { QuakeySpawn config = { + .name = "ms", .state_size = sizeof(MetadataServer), .init_func = metadata_server_init, .tick_func = metadata_server_tick, @@ -161,6 +163,7 @@ int main(void) // Chunk Server { QuakeySpawn config = { + .name = "cs", .state_size = sizeof(ChunkServer), .init_func = chunk_server_init, .tick_func = chunk_server_tick, diff --git a/src/metadata_server.c b/src/metadata_server.c index 1354c78..294fb90 100644 --- a/src/metadata_server.c +++ b/src/metadata_server.c @@ -9,7 +9,8 @@ #include "message.h" #include "metadata_server.h" -#define MS_TRACE(fmt, ...) fprintf(stderr, "MS: " fmt "\n", ##__VA_ARGS__); +#define MS_TRACE(fmt, ...) {} +//#define MS_TRACE(fmt, ...) fprintf(stderr, "MS: " fmt "\n", ##__VA_ARGS__); static void chunk_server_peer_init(ChunkServerPeer *chunk_server, Time current_time) {