Skip to content

Commit

Permalink
test: add function parsing markers passed by pmreorder
Browse files Browse the repository at this point in the history
  • Loading branch information
nofuturre committed Aug 9, 2022
1 parent aaf724a commit a3a1765
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 13 deletions.
51 changes: 51 additions & 0 deletions src/test/pmreorder_stack/pmreorder0.log.match
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,57 @@ Store [3]:
WARNING:pmreorder:File $(nW)/testfile (base: 0x$(nW), size: 0x$(nW)) inconsistent
WARNING:pmreorder:Call trace:

WARNING:pmreorder:File $(nW)/testfile (base: 0x$(nW), size: 0x$(nW)) inconsistent
WARNING:pmreorder:Call trace:
Store [0]:
by $(nW): write_fields (pmreorder_stack.c:$(N))
by $(nW): main (pmreorder_stack.c:$(N))

WARNING:pmreorder:File $(nW)/testfile (base: 0x$(nW), size: 0x$(nW)) inconsistent
WARNING:pmreorder:Call trace:
Store [0]:
by $(nW): write_fields (pmreorder_stack.c:$(N))
by $(nW): main (pmreorder_stack.c:$(N))
Store [1]:
by $(nW): write_fields (pmreorder_stack.c:$(N))
by $(nW): main (pmreorder_stack.c:$(N))

WARNING:pmreorder:File $(nW)/testfile (base: 0x$(nW), size: 0x$(nW)) inconsistent
WARNING:pmreorder:Call trace:
Store [0]:
by $(nW): write_fields (pmreorder_stack.c:$(N))
by $(nW): main (pmreorder_stack.c:$(N))
Store [1]:
by $(nW): write_fields (pmreorder_stack.c:$(N))
by $(nW): main (pmreorder_stack.c:$(N))
Store [2]:
by $(nW): write_fields (pmreorder_stack.c:$(N))
by $(nW): main (pmreorder_stack.c:$(N))

WARNING:pmreorder:File $(nW)/testfile (base: 0x$(nW), size: 0x$(nW)) inconsistent
WARNING:pmreorder:Call trace:
Store [0]:
by $(nW): write_fields (pmreorder_stack.c:$(N))
by $(nW): main (pmreorder_stack.c:$(N))
Store [1]:
by $(nW): write_fields (pmreorder_stack.c:$(N))
by $(nW): main (pmreorder_stack.c:$(N))
Store [2]:
by $(nW): write_fields (pmreorder_stack.c:$(N))
by $(nW): main (pmreorder_stack.c:$(N))
Store [3]:
by $(nW): write_fields (pmreorder_stack.c:$(N))
by $(nW): main (pmreorder_stack.c:$(N))

WARNING:pmreorder:File $(nW)/testfile (base: 0x$(nW), size: 0x$(nW)) inconsistent
WARNING:pmreorder:Call trace:

WARNING:pmreorder:File $(nW)/testfile (base: 0x$(nW), size: 0x$(nW)) inconsistent
WARNING:pmreorder:Call trace:
Store [0]:
by $(nW): write_fields (pmreorder_stack.c:$(N))
by $(nW): main (pmreorder_stack.c:$(N))

WARNING:pmreorder:File $(nW)/testfile (base: 0x$(nW), size: 0x$(nW)) inconsistent
WARNING:pmreorder:Call trace:
Store [0]:
Expand Down
39 changes: 27 additions & 12 deletions src/test/pmreorder_stack/pmreorder_stack.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -35,31 +35,28 @@ struct fields {
};

/*
* write_fields -- (internal) write data in a consistent manner.
* write_fields -- (internal) write data in a inconsistent 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;
fieldsp->c = 1;
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;
fieldsp->g = 1;
fieldsp->h = 1;
pmem_persist(&fieldsp->e, sizeof(int) * 4);

VALGRIND_EMIT_LOG("FIELDS_PACK_TWO.END");

fieldsp->i = 1;
fieldsp->j = 1;
fieldsp->k = 1;
Expand All @@ -71,12 +68,23 @@ 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;
else {
for (int i = 0; i < (int)log->markers_no; i++)
consistency &= strcmp(log->markers[i], sm.markers[i]);
}
}

delete_markers(log);
return consistency;
}

Expand All @@ -103,16 +111,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);
}
Expand Down
48 changes: 47 additions & 1 deletion src/test/unittest/unittest.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
*/
Expand Down

0 comments on commit a3a1765

Please sign in to comment.