Skip to content

Commit 85eae34

Browse files
Switch unit tests to jerry-libc.
JerryScript-DCO-1.0-Signed-off-by: Ruben Ayrapetyan [email protected]
1 parent d64a46e commit 85eae34

12 files changed

+44
-23
lines changed

CMakeLists.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ project (Jerry CXX C ASM)
234234
set(FLAGS_COMMON_RELEASE "-Os -nostdlib")
235235

236236
# Unit tests
237-
set(FLAGS_COMMON_UNITTESTS "-O3 -nodefaultlibs")
237+
set(FLAGS_COMMON_UNITTESTS "-O3 -nostdlib")
238238

239239
# Include directories
240240
# Core interface
@@ -310,8 +310,9 @@ project (Jerry CXX C ASM)
310310
add_subdirectory(plugins)
311311

312312
# Targets declaration
313+
string(TOLOWER "${PLATFORM_EXT}" PLATFORM_L)
314+
313315
function(declare_targets_for_build_mode BUILD_MODE)
314-
string(TOLOWER "${PLATFORM_EXT}" PLATFORM_L)
315316
set(TARGET_NAME ${BUILD_MODE_PREFIX_${BUILD_MODE}}.${PLATFORM_L})
316317
set(PLUGINS_TARGET_NAME ${BUILD_MODE_PREFIX_${BUILD_MODE}}.plugins.${PLATFORM_L}.lib)
317318
set(LIBC_TARGET_NAME ${BUILD_MODE_PREFIX_${BUILD_MODE}}.jerry-libc.${PLATFORM_L}.lib)
@@ -424,6 +425,7 @@ project (Jerry CXX C ASM)
424425
set(TARGET_NAME unit-${TARGET_NAME})
425426

426427
set(CORE_TARGET_NAME unittests.jerry-core)
428+
set(LIBC_TARGET_NAME unittests.jerry-libc.${PLATFORM_L}.lib)
427429
set(FDLIBM_TARGET_NAME unittests.jerry-fdlibm${SUFFIX_THIRD_PARTY_LIB})
428430

429431
add_executable(${TARGET_NAME} ${SOURCE_UNIT_TEST_MAIN})
@@ -432,7 +434,8 @@ project (Jerry CXX C ASM)
432434
set_property(TARGET ${TARGET_NAME}
433435
PROPERTY LINK_FLAGS "${COMPILE_FLAGS_JERRY} ${CXX_FLAGS_JERRY} ${FLAGS_COMMON_UNITTESTS} ${LINKER_FLAGS_COMMON}")
434436
target_include_directories(${TARGET_NAME} PRIVATE ${INCLUDE_CORE_INTERFACE})
435-
target_link_libraries(${TARGET_NAME} ${CORE_TARGET_NAME} ${FDLIBM_TARGET_NAME} ${PREFIX_IMPORTED_LIB}libc
437+
target_include_directories(${TARGET_NAME} SYSTEM PRIVATE ${INCLUDE_LIBC_INTERFACE})
438+
target_link_libraries(${TARGET_NAME} ${CORE_TARGET_NAME} ${LIBC_TARGET_NAME} ${FDLIBM_TARGET_NAME}
436439
${PREFIX_IMPORTED_LIB}libgcc ${PREFIX_IMPORTED_LIB}libgcc_eh)
437440

438441
add_cppcheck_target(${TARGET_NAME})

jerry-libc/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,4 @@ set(COMPILE_FLAGS_LIBC "${COMPILE_FLAGS_JERRY} ${C_FLAGS_JERRY}")
139139

140140
declare_targets_for_build_mode(DEBUG)
141141
declare_targets_for_build_mode(RELEASE)
142+
declare_targets_for_build_mode(UNITTESTS)

tests/unit/test-api.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ const jerry_api_char_ptr_t magic_string_items[] =
218218
int
219219
main (void)
220220
{
221+
TEST_INIT ();
222+
221223
jerry_init (JERRY_FLAG_EMPTY);
222224

223225
bool is_ok;

tests/unit/test-common.h

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,32 @@
2424
#include <string.h>
2525
#include <sys/time.h>
2626

27-
using namespace std;
28-
29-
#define TEST_RANDOMIZE() \
27+
/**
28+
* Test initialization statement that should be included
29+
* at the beginning of main function in every unit test.
30+
*/
31+
#define TEST_INIT() \
3032
do \
3133
{ \
32-
struct timeval current_time; \
33-
gettimeofday (&current_time, NULL); \
34-
\
35-
time_t seconds = current_time.tv_sec; \
36-
suseconds_t microseconds = current_time.tv_usec; \
37-
\
38-
uint32_t seed = (uint32_t) (seconds + microseconds); \
39-
\
40-
printf ("TEST_RANDOMIZE: seed is %u\n", seed); \
41-
\
34+
FILE *f_rnd = fopen ("/dev/urandom", "r"); \
35+
\
36+
if (f_rnd == NULL) \
37+
{ \
38+
return 1; \
39+
} \
40+
\
41+
uint32_t seed; \
42+
\
43+
size_t bytes_read = fread (&seed, 1, sizeof (seed), f_rnd); \
44+
\
45+
fclose (f_rnd); \
46+
\
47+
if (bytes_read != sizeof (seed)) \
48+
{ \
49+
return 1; \
50+
} \
51+
\
4252
srand (seed); \
43-
} \
44-
while (0)
53+
} while (0)
4554

4655
#endif /* TEST_COMMON_H */

tests/unit/test-heap.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ int
8282
main (int __attr_unused___ argc,
8383
char __attr_unused___ **argv)
8484
{
85-
TEST_RANDOMIZE ();
85+
TEST_INIT ();
8686

8787
mem_heap_init (test_native_heap, sizeof (test_native_heap));
8888

tests/unit/test-literal-storage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ int
5858
main (int __attr_unused___ argc,
5959
char __attr_unused___ **argv)
6060
{
61-
TEST_RANDOMIZE ();
61+
TEST_INIT ();
6262

6363
const ecma_char_t *ptrs[test_sub_iters];
6464
ecma_number_t numbers[test_sub_iters];

tests/unit/test-number-to-string.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ int
2525
main (int __attr_unused___ argc,
2626
char __attr_unused___ **argv)
2727
{
28+
TEST_INIT ();
29+
2830
const ecma_char_t* zt_strings[] =
2931
{
3032
(const ecma_char_t*) "1",

tests/unit/test-parser.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ int
6969
main (int __attr_unused___ argc,
7070
char __attr_unused___ **argv)
7171
{
72+
TEST_INIT ();
73+
7274
char program[] = "a=1;var a;";
7375
bool is_ok;
7476

tests/unit/test-pool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ int
3737
main (int __attr_unused___ argc,
3838
char __attr_unused___ **argv)
3939
{
40-
TEST_RANDOMIZE ();
40+
TEST_INIT ();
4141

4242
for (uint32_t i = 0; i < test_iters; i++)
4343
{

tests/unit/test-poolman.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ int
3737
main (int __attr_unused___ argc,
3838
char __attr_unused___ **argv)
3939
{
40-
TEST_RANDOMIZE ();
40+
TEST_INIT ();
4141

4242
mem_init ();
4343

0 commit comments

Comments
 (0)