Skip to content

Commit 0494778

Browse files
i#5365 AArch64 tests: fix drcacheoff.scale_time test for Ubuntu 24.04 (#7761)
Fix tool.drcacheoff.scale_time unit test by replacing the calls to malloc() with calls to rand() which the compiler cannot optimize out. It seems that g++ 11.5 was able to optimize out the calls to malloc() and the resulting code was too fast for the timers to fire. Issue: #5365
1 parent 5c81659 commit 0494778

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

clients/drcachesim/tests/scale_time.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -144,24 +144,20 @@ disable_timers(void)
144144
assert(res == 0);
145145
}
146146

147-
static void
147+
static int
148148
do_some_work(void)
149149
{
150150
enable_timers();
151151
// Do real work to trigger CPU time-based timers.
152-
static const int ITERS = 5000;
153-
double val = ITERS / 33.;
154-
double **vals = (double **)calloc(ITERS, sizeof(double *));
155-
for (int i = 0; i < ITERS; ++i) {
156-
vals[i] = (double *)malloc(sizeof(double));
157-
*vals[i] = sin(val);
158-
val += *vals[i];
159-
vals[i] = (double *)realloc(vals[i], 2 * sizeof(double));
160-
}
161-
for (int i = 0; i < ITERS; ++i)
162-
free(vals[i]);
163-
free(vals);
152+
// Use rand() so that the compiler cannot optimise out some of the work.
153+
int total = 0;
154+
155+
for (int i = 0; i < 100000; i++)
156+
total += rand() % 100;
157+
164158
disable_timers();
159+
160+
return total;
165161
}
166162

167163
/****************************************************************************
@@ -272,6 +268,7 @@ int
272268
test_main(int argc, const char *argv[])
273269
{
274270
create_posix_timer();
271+
srand(time(NULL)); // randomize seed
275272

276273
std::cerr << "gathering no-scaling trace\n";
277274
std::string dir_default = gather_trace("", "default");

0 commit comments

Comments
 (0)