diff --git a/src/test/pmreorder_stack/pmreorder_stack.c b/src/test/pmreorder_stack/pmreorder_stack.c index de740f8af97..fa7d745a279 100644 --- a/src/test/pmreorder_stack/pmreorder_stack.c +++ b/src/test/pmreorder_stack/pmreorder_stack.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2018-2019, Intel Corporation */ +/* Copyright 2018-2022, Intel Corporation */ /* * pmreorder_stack.c -- unit test for engines pmreorder stack @@ -37,12 +37,11 @@ struct fields { /* * write_fields -- (internal) write data in a consistent manner. */ -static void -write_fields(struct fields *fieldsp) +static void write_fields(struct fields *fieldsp, struct markers sm) { - VALGRIND_EMIT_LOG("FIELDS_PACK_TWO.BEGIN"); + VALGRIND_EMIT_LOG(sm.markers[0]); - VALGRIND_EMIT_LOG("FIELDS_PACK_ONE.BEGIN"); + VALGRIND_EMIT_LOG(sm.markers[1]); fieldsp->a = 1; fieldsp->b = 1; @@ -50,7 +49,7 @@ write_fields(struct fields *fieldsp) fieldsp->d = 1; pmem_persist(&fieldsp->a, sizeof(int) * 4); - VALGRIND_EMIT_LOG("FIELDS_PACK_ONE.END"); + VALGRIND_EMIT_LOG(sm.markers[2]); fieldsp->e = 1; fieldsp->f = 1; @@ -58,7 +57,7 @@ write_fields(struct fields *fieldsp) fieldsp->h = 1; pmem_persist(&fieldsp->e, sizeof(int) * 4); - VALGRIND_EMIT_LOG("FIELDS_PACK_TWO.END"); + VALGRIND_EMIT_LOG(sm.markers[3]); fieldsp->i = 1; fieldsp->j = 1; @@ -71,12 +70,28 @@ write_fields(struct fields *fieldsp) * check_consistency -- (internal) check struct fields consistency. */ static int -check_consistency(struct fields *fieldsp) +check_consistency(struct fields *fieldsp, struct markers sm) { int consistency = 1; if (fieldsp->e == 1 && fieldsp->f == 0) consistency = 0; + struct markers *log = get_markers(os_getenv("PMREORDER_MARKERS")); + if (log) { + if (log->markers_no != sm.markers_no) + consistency = 1; + // XXX: parse markers this and handle all cases... + for (int i = 0; i < (int)log->markers_no; i++) + consistency &= strcmp(log->markers[i], sm.markers[i]); + } + if (consistency) { + consistency &= (fieldsp->a == 1 && fieldsp->b == 1 && + fieldsp->c == 1 && fieldsp->d == 1) && + (fieldsp->i == 0 && fieldsp->j == 0 && + fieldsp->k == 0 && fieldsp->l == 0); + } + + delete_markers(log); return consistency; } @@ -103,16 +118,23 @@ main(int argc, char *argv[]) char opt = argv[1][0]; + char *logs[] = {"FIELDS_PACK_TWO.BEGIN", "FIELDS_PACK_ONE.BEGIN", + "FIELDS_PACK_ONE.END", "FIELDS_PACK_TWO.END"}; + + struct markers stack_markers; + stack_markers.markers_no = 4; + stack_markers.markers = logs; + /* clear the struct to get a consistent start state for writing */ if (strchr("w", opt)) pmem_memset_persist(fieldsp, 0, sizeof(*fieldsp)); switch (opt) { case 'w': - write_fields(fieldsp); + write_fields(fieldsp, stack_markers); break; case 'c': - return check_consistency(fieldsp); + return check_consistency(fieldsp, stack_markers); default: UT_FATAL("Unrecognized option %c", opt); } diff --git a/src/test/unittest/unittest.h b/src/test/unittest/unittest.h index 3a55cf22928..b65bf7255bf 100644 --- a/src/test/unittest/unittest.h +++ b/src/test/unittest/unittest.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: BSD-3-Clause */ -/* Copyright 2014-2020, Intel Corporation */ +/* Copyright 2014-2022, Intel Corporation */ /* * unittest.h -- the mundane stuff shared by all unit tests @@ -668,6 +668,11 @@ struct test_case { int (*func)(const struct test_case *tc, int argc, char *argv[]); }; +struct markers { + unsigned markers_no; + char **markers; +}; + /* * get_tc -- return test case of specified name */ @@ -750,6 +755,47 @@ if (off != sizeof(type))\ STR(type), last, STR(type), sizeof(type), off);\ } while (0) +/* + * get_markers - return list of the markers passed by pmreorder + */ +static inline struct markers * +get_markers(char *input) +{ + if (!input) + return NULL; + + struct markers *log = malloc(sizeof(struct markers)); + char *delim = "|"; + + log->markers_no = 1; + for (char *s = input; *s != '\0'; s++) + if (strncmp(s, delim, strlen(delim)) == 0) + log->markers_no++; + log->markers = malloc(log->markers_no * sizeof(char *)); + + char *token = strtok(input, delim); + int i = 0; + + while (token != NULL) { + log->markers[i] = malloc(strlen(token) * sizeof(char)); + strncpy(log->markers[i], token, strlen(token)); + i++; + printf(" %s\n", token); + token = strtok(NULL, delim); + } + + return log; +} + +static inline void +delete_markers(struct markers *log) +{ + for (unsigned i = 0; i < log->markers_no; i++) + free(log->markers[i]); + free(log->markers); + free(log); +} + /* * AddressSanitizer */