Skip to content

Commit 922db70

Browse files
committed
Fix: default random seed might exceed the limit
1 parent 39dbd03 commit 922db70

File tree

3 files changed

+16
-22
lines changed

3 files changed

+16
-22
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## v3.0.4
44

5+
### Fixed
6+
1. Fix: default random seed might exceed the limit.
7+
58
### Features
69
1. Automatic disable thread support if `Threads` not found.
710
2. Test case can be unregistered by `cutest_unregister_case()`.

include/cutest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ extern "C" {
115115
/**
116116
* @brief Development version.
117117
*/
118-
#define CUTEST_VERSION_PREREL 2
118+
#define CUTEST_VERSION_PREREL 3
119119

120120
/**
121121
* @brief Ensure the api is exposed as C function.

src/cutest.c

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3081,15 +3081,14 @@ static void _cutest_setup_once(void)
30813081
{
30823082
token = 1;
30833083
_cutest_setup_type();
3084-
_cutest_srand(1);
30853084
}
30863085
}
30873086

30883087
static void _cutest_prepare(void)
30893088
{
30903089
cutest_porting_timespec_t seed;
30913090
cutest_porting_clock_gettime(&seed);
3092-
cutest_porting_srand((unsigned long)seed.tv_sec);
3091+
_cutest_srand((unsigned long)seed.tv_sec);
30933092

30943093
g_test_ctx.runtime.tid = cutest_porting_gettid();
30953094
g_test_ctx.counter.repeat.repeat = 1;
@@ -3131,6 +3130,15 @@ static int _cutest_setup_arg_break_on_failure(void)
31313130
return 0;
31323131
}
31333132

3133+
static void _cutest_cleanup(void)
3134+
{
3135+
cutest_map_t case_table = g_test_ctx.case_table;
3136+
cutest_map_t type_table = g_test_ctx.type_table;
3137+
cutest_porting_memset(&g_test_ctx, 0, sizeof(g_test_ctx));
3138+
g_test_ctx.case_table = case_table;
3139+
g_test_ctx.type_table = type_table;
3140+
}
3141+
31343142
/**
31353143
* @brief Setup test context
31363144
* @param[in] argc The number of command line argument.
@@ -3170,16 +3178,9 @@ static int _cutest_setup(int argc, char* argv[], FILE* out, const cutest_hook_t*
31703178
continue;\
31713179
} while (0)
31723180

3173-
/* Do soft clear. */
3174-
{
3175-
cutest_map_t case_table = g_test_ctx.case_table;
3176-
cutest_map_t type_table = g_test_ctx.type_table;
3177-
cutest_porting_memset(&g_test_ctx, 0, sizeof(g_test_ctx));
3178-
g_test_ctx.case_table = case_table;
3179-
g_test_ctx.type_table = type_table;
3180-
}
3181-
31823181
_cutest_setup_once();
3182+
3183+
_cutest_cleanup();
31833184
_cutest_prepare();
31843185

31853186
g_test_ctx.out = out;
@@ -3233,16 +3234,6 @@ static void _cutest_run_all_test_once(void)
32333234
_cutest_show_report(&tv_total_start, &tv_total_end);
32343235
}
32353236

3236-
static void _cutest_cleanup(void)
3237-
{
3238-
cutest_porting_memset(&g_test_ctx.runtime, 0, sizeof(g_test_ctx.runtime));
3239-
cutest_porting_memset(&g_test_ctx.counter, 0, sizeof(g_test_ctx.counter));
3240-
cutest_porting_memset(&g_test_ctx.mask, 0, sizeof(g_test_ctx.mask));
3241-
cutest_porting_memset(&g_test_ctx.filter, 0, sizeof(g_test_ctx.filter));
3242-
3243-
g_test_ctx.hook = NULL;
3244-
}
3245-
32463237
static void _cutest_show_information(void)
32473238
{
32483239
#if CUTEST_VERSION_PREREL

0 commit comments

Comments
 (0)