summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-19 09:31:21 +0200
committerPaul Buetow <paul@buetow.org>2026-03-19 09:31:21 +0200
commit2e73e8906e5ba3f81578f1700f7478c94c92acb8 (patch)
treeb11566e6c4710421ec2d53e4234aae976c785e2e
parent75abacb64468952f2202e38f35d12b8f2011d7c8 (diff)
fix: restore replay metadata version checks (task 463)
-rw-r--r--ioriot/src/defaults.h2
-rw-r--r--ioriot/src/replay/replay.c44
-rw-r--r--ioriot/src/replay/replay.h5
-rw-r--r--ioriot/src/utests.c4
4 files changed, 54 insertions, 1 deletions
diff --git a/ioriot/src/defaults.h b/ioriot/src/defaults.h
index b79e026..404f83a 100644
--- a/ioriot/src/defaults.h
+++ b/ioriot/src/defaults.h
@@ -21,6 +21,8 @@
#define CAPTURE_VERSION 3
/** Version of the supported .replay format */
#define REPLAY_VERSION 2
+/** Meta header key for the supported .replay format version */
+#define REPLAY_VERSION_KEY "replay_version"
/** Max amount of tokens per line in the .capture file */
#define MAX_TOKENS 10
/** Max line length in either .capture or .replay file */
diff --git a/ioriot/src/replay/replay.c b/ioriot/src/replay/replay.c
index 332d528..288aa58 100644
--- a/ioriot/src/replay/replay.c
+++ b/ioriot/src/replay/replay.c
@@ -27,7 +27,7 @@ void replay_extract_header(options_s *opts, FILE *replay_fd, long *num_vsizes,
meta_read_start(m);
long version = 0;
- if (meta_read_l(m, "version", &version)) {
+ if (meta_read_l(m, REPLAY_VERSION_KEY, &version)) {
Put("Replay version is '%ld'", version);
if (version != REPLAY_VERSION) {
Error(".replay file of incompatible version, got %x, expected %x",
@@ -78,6 +78,48 @@ void replay_extract_header(options_s *opts, FILE *replay_fd, long *num_vsizes,
meta_destroy(m);
}
+void replay_test(void)
+{
+ FILE *replay_fd = tmpfile();
+ assert(replay_fd != NULL);
+
+ meta_s *meta = meta_new(replay_fd);
+ meta_reserve(meta);
+ meta_write_start(meta);
+ meta_write_l(meta, REPLAY_VERSION_KEY, REPLAY_VERSION);
+ meta_write_s(meta, "user", "metauser");
+ meta_write_s(meta, "name", "metatest");
+ meta_write_l(meta, "num_vsizes", 11);
+ meta_write_l(meta, "num_mapped_pids", 22);
+ meta_write_l(meta, "num_mapped_fds", 33);
+ meta_write_l(meta, "num_lines", 44);
+ meta_destroy(meta);
+
+ rewind(replay_fd);
+ meta = meta_new(replay_fd);
+ meta_read_start(meta);
+ long wrong_version = -1;
+ assert(!meta_read_l(meta, "version", &wrong_version));
+ meta_destroy(meta);
+
+ rewind(replay_fd);
+ options_s opts = {0};
+ long num_vsizes = 0, num_pids = 0, num_fds = 0, num_lines = 0;
+ replay_extract_header(&opts, replay_fd, &num_vsizes, &num_pids, &num_fds,
+ &num_lines);
+
+ assert(num_vsizes == 11);
+ assert(num_pids == 22);
+ assert(num_fds == 33);
+ assert(num_lines == 44);
+ assert(Eq(opts.user, "metauser"));
+ assert(Eq(opts.name, "metatest"));
+
+ free(opts.user);
+ free(opts.name);
+ fclose(replay_fd);
+}
+
status_e replay_run(options_s *opts)
{
status_e status = SUCCESS;
diff --git a/ioriot/src/replay/replay.h b/ioriot/src/replay/replay.h
index dcc3d84..c405b4f 100644
--- a/ioriot/src/replay/replay.h
+++ b/ioriot/src/replay/replay.h
@@ -43,4 +43,9 @@ status_e replay_run(options_s *opts);
void replay_extract_header(options_s *opts, FILE *replay_fd, long *num_vsizes,
long *num_pids, long *num_fds,long *num_lines);
+/**
+ * @brief Unit tests replay header parsing
+ */
+void replay_test(void);
+
#endif // REPLAY_H
diff --git a/ioriot/src/utests.c b/ioriot/src/utests.c
index 8f65866..1e332f9 100644
--- a/ioriot/src/utests.c
+++ b/ioriot/src/utests.c
@@ -19,6 +19,7 @@
#include "datas/hmap.h"
#include "datas/list.h"
#include "datas/rbuffer.h"
+#include "replay/replay.h"
#include "utils/utils.h"
void utests_run()
@@ -38,6 +39,9 @@ void utests_run()
fprintf(stderr, "Running utils_test()\n");
utils_test();
+ fprintf(stderr, "Running replay_test()\n");
+ replay_test();
+
//fprintf(stderr, "Running amap_test()\n");
//amap_test();