Skip to content

Commit 4d4ca8f

Browse files
[libc] add simple tests for vDSO symbols
1 parent ce5a192 commit 4d4ca8f

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_ARCHITECTURE})
22
add_subdirectory(${LIBC_TARGET_ARCHITECTURE})
33
endif()
4+
5+
add_libc_test(
6+
vdso_test
7+
SUITE libc-osutil-tests
8+
SRCS vdso_test.cpp
9+
DEPENDS
10+
libc.src.__support.OSUtil.vdso
11+
libc.include.llvm-libc-types.struct_timeval # TODO: update this to proxy header once available
12+
)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//===-- Unittests for x86_64 syscalls -------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "llvm-libc-types/struct_timeval.h"
10+
#include "src/__support/OSUtil/vdso.h"
11+
#include "test/UnitTest/Test.h"
12+
13+
namespace LIBC_NAMESPACE {
14+
TEST(LlvmLibcOSUtilVDSOTest, SymbolsDefined) {
15+
// for now, we simply test all symbols are provided.
16+
for (size_t i = 0; i < static_cast<size_t>(vdso::VDSOSym::VDSOSymCount); ++i)
17+
EXPECT_NE(vdso::get_symbol(static_cast<vdso::VDSOSym>(i)),
18+
static_cast<void *>(nullptr));
19+
}
20+
21+
#ifdef LIBC_VDSO_HAS_GETTIMEOFDAY
22+
TEST(LlvmLibcOSUtilVDSOTest, GetTimeOfDay) {
23+
using FuncTy = int (*)(timeval *, struct timezone *);
24+
auto func =
25+
reinterpret_cast<FuncTy>(vdso::get_symbol(vdso::VDSOSym::GetTimeOfDay));
26+
timeval tv;
27+
EXPECT_EQ(func(&tv, nullptr), 0);
28+
// hopefully people are not building time machines using our libc.
29+
EXPECT_GT(tv.tv_sec, static_cast<decltype(tv.tv_sec)>(0));
30+
}
31+
#endif
32+
33+
} // namespace LIBC_NAMESPACE

0 commit comments

Comments
 (0)