|
| 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