From: Amir Goldstein Date: Wed, 23 Aug 2017 15:49:12 +0000 (+0300) Subject: fsx: fixes to random seed X-Git-Tag: v2022.05.01~1904 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=14ceec4027adc9addba5020642c08c77497095da;p=xfstests-dev.git fsx: fixes to random seed Not sure why, but with initstate()/setstate(), fsx generates same events regadless of the input seed argument. Change to use srandom() to fix the problem. Add pid to auto random seed, so parallel fsx executions with auto seed will use different seed values. At this time there are 6 tests that use fsx, out of which: 2 use -S 0 as seed (gettime()) - generic/{075,112} 2 do not specify seed (default = 1) - generic/{091,263} 1 uses explicit constant seed - generic/127 1 uses explicit $RANDOM seed - generic/231 This change affects all those tests. The tests that intended to randomize the seed will now really randomize the seed. The tests that intended to use a constant seed will still use a constant seed, but resulting event sequence will be different than before this change. Signed-off-by: Amir Goldstein Reviewed-by: Eryu Guan Signed-off-by: Eryu Guan --- diff --git a/ltp/fsx.c b/ltp/fsx.c index 3713bbe3..572df754 100644 --- a/ltp/fsx.c +++ b/ltp/fsx.c @@ -116,7 +116,6 @@ int fd; /* fd for our test file */ blksize_t block_size = 0; off_t file_size = 0; off_t biggest = 0; -char state[256]; unsigned long testcalls = 0; /* calls to function "test" */ unsigned long simulatedopcount = 0; /* -b flag */ @@ -1909,8 +1908,10 @@ main(int argc, char **argv) break; case 'S': seed = getnum(optarg, &endp); - if (seed == 0) + if (seed == 0) { seed = time(0) % 10000; + seed += (int)getpid(); + } if (!quiet) fprintf(stdout, "Seed set to %d\n", seed); if (seed < 0) @@ -1948,8 +1949,7 @@ main(int argc, char **argv) signal(SIGUSR1, cleanup); signal(SIGUSR2, cleanup); - initstate(seed, state, 256); - setstate(state); + srandom(seed); fd = open(fname, O_RDWR|(lite ? 0 : O_CREAT|O_TRUNC)|o_direct, 0666); if (fd < 0) {