Compare commits
8 Commits
b95f0498b6
...
ec4195f18a
Author | SHA1 | Date | |
---|---|---|---|
ec4195f18a | |||
062ad7ae80 | |||
aad07611c7 | |||
0dcb66f143 | |||
331c25b0e6 | |||
e50844be06 | |||
4dd7c98c1a | |||
63bad2e99a |
5
.github/workflows/cd.yml
vendored
5
.github/workflows/cd.yml
vendored
@ -13,7 +13,7 @@ jobs:
|
||||
windows:
|
||||
timeout-minutes: 15
|
||||
|
||||
runs-on: windows-latest
|
||||
runs-on: windows-2019
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
@ -34,6 +34,9 @@ jobs:
|
||||
- name: Build
|
||||
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4
|
||||
|
||||
- name: temp test
|
||||
run: ${{github.workspace}}/build/bin/mono_time_test.exe
|
||||
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: ${{ github.event.repository.name }}-windows-msvc-x86_64
|
||||
|
6
.github/workflows/ci.yml
vendored
6
.github/workflows/ci.yml
vendored
@ -29,6 +29,9 @@ jobs:
|
||||
- name: Build
|
||||
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4
|
||||
|
||||
- name: temp test
|
||||
run: ${{github.workspace}}/build/bin/mono_time_test
|
||||
|
||||
macos:
|
||||
timeout-minutes: 10
|
||||
|
||||
@ -72,3 +75,6 @@ jobs:
|
||||
- name: Build
|
||||
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4
|
||||
|
||||
- name: temp test
|
||||
run: ${{github.workspace}}/build/bin/mono_time_test.exe
|
||||
|
||||
|
6
external/toxcore/CMakeLists.txt
vendored
6
external/toxcore/CMakeLists.txt
vendored
@ -203,6 +203,10 @@ add_executable(DHT_Bootstrap EXCLUDE_FROM_ALL
|
||||
${TOX_DIR}testing/misc_tools.h
|
||||
${TOX_DIR}testing/misc_tools.c
|
||||
)
|
||||
|
||||
target_link_libraries(DHT_Bootstrap toxcore)
|
||||
|
||||
add_executable(mono_time_test
|
||||
./mono_time_test.cc
|
||||
)
|
||||
target_link_libraries(mono_time_test toxcore)
|
||||
target_compile_features(mono_time_test PUBLIC cxx_std_11)
|
||||
|
138
external/toxcore/mono_time_test.cc
vendored
Normal file
138
external/toxcore/mono_time_test.cc
vendored
Normal file
@ -0,0 +1,138 @@
|
||||
#include "./c-toxcore/toxcore/mono_time.h"
|
||||
|
||||
#ifdef NDEBUG
|
||||
#undef NDEBUG
|
||||
#include <cassert>
|
||||
#else
|
||||
#include <cassert>
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
|
||||
#define TEST(x, y) bool run_test_##x##y(void)
|
||||
|
||||
#define ASSERT_NE(x, y) assert((x) != (y))
|
||||
#define EXPECT_GT(x, y) assert((x) > (y))
|
||||
#define EXPECT_FALSE(x) assert(!(x))
|
||||
#define EXPECT_TRUE(x) assert((x))
|
||||
#define EXPECT_EQ(x, y) assert((x) == (y))
|
||||
|
||||
TEST(MonoTime, UnixTimeIncreasesOverTime)
|
||||
{
|
||||
const Memory *mem = system_memory();
|
||||
Mono_Time *mono_time = mono_time_new(mem, nullptr, nullptr);
|
||||
ASSERT_NE(mono_time, nullptr);
|
||||
|
||||
mono_time_update(mono_time);
|
||||
uint64_t const start = mono_time_get(mono_time);
|
||||
|
||||
while (start == mono_time_get(mono_time)) {
|
||||
mono_time_update(mono_time);
|
||||
}
|
||||
|
||||
uint64_t const end = mono_time_get(mono_time);
|
||||
EXPECT_GT(end, start);
|
||||
|
||||
mono_time_free(mem, mono_time);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
TEST(MonoTime, IsTimeout)
|
||||
{
|
||||
const Memory *mem = system_memory();
|
||||
Mono_Time *mono_time = mono_time_new(mem, nullptr, nullptr);
|
||||
ASSERT_NE(mono_time, nullptr);
|
||||
|
||||
uint64_t const start = mono_time_get(mono_time);
|
||||
EXPECT_FALSE(mono_time_is_timeout(mono_time, start, 1));
|
||||
|
||||
while (start == mono_time_get(mono_time)) {
|
||||
mono_time_update(mono_time);
|
||||
}
|
||||
|
||||
EXPECT_TRUE(mono_time_is_timeout(mono_time, start, 1));
|
||||
|
||||
mono_time_free(mem, mono_time);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
TEST(MonoTime, IsTimeoutReal)
|
||||
{
|
||||
const Memory *mem = system_memory();
|
||||
Mono_Time *mono_time = mono_time_new(mem, nullptr, nullptr);
|
||||
ASSERT_NE(mono_time, nullptr);
|
||||
|
||||
uint64_t const start = mono_time_get(mono_time);
|
||||
EXPECT_FALSE(mono_time_is_timeout(mono_time, start, 5));
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
mono_time_update(mono_time);
|
||||
|
||||
// should still not have timed out (5sec) after sleeping ~20ms
|
||||
EXPECT_FALSE(mono_time_is_timeout(mono_time, start, 5));
|
||||
|
||||
mono_time_free(mem, mono_time);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
TEST(MonoTime, CustomTime)
|
||||
{
|
||||
const Memory *mem = system_memory();
|
||||
Mono_Time *mono_time = mono_time_new(mem, nullptr, nullptr);
|
||||
ASSERT_NE(mono_time, nullptr);
|
||||
|
||||
uint64_t test_time = current_time_monotonic(mono_time) + 42137;
|
||||
|
||||
mono_time_set_current_time_callback(
|
||||
mono_time, [](void *user_data) { return *static_cast<uint64_t *>(user_data); }, &test_time);
|
||||
mono_time_update(mono_time);
|
||||
|
||||
EXPECT_EQ(current_time_monotonic(mono_time), test_time);
|
||||
|
||||
uint64_t const start = mono_time_get(mono_time);
|
||||
|
||||
test_time += 7000;
|
||||
|
||||
mono_time_update(mono_time);
|
||||
EXPECT_EQ(mono_time_get(mono_time) - start, 7);
|
||||
|
||||
EXPECT_EQ(current_time_monotonic(mono_time), test_time);
|
||||
|
||||
mono_time_free(mem, mono_time);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
if (!run_test_MonoTimeUnixTimeIncreasesOverTime()) {
|
||||
std::cerr << "MonoTimeUnixTimeIncreasesOverTime() failed\n";
|
||||
return -1;
|
||||
}
|
||||
std::cout << "MonoTimeUnixTimeIncreasesOverTime() succeeded\n";
|
||||
|
||||
if (!run_test_MonoTimeIsTimeout()) {
|
||||
std::cerr << "MonoTimeIsTimeout() failed\n";
|
||||
return -1;
|
||||
}
|
||||
std::cout << "MonoTimeIsTimeout() succeeded\n";
|
||||
|
||||
if (!run_test_MonoTimeIsTimeoutReal()) {
|
||||
std::cerr << "MonoTimeIsTimeoutReal() failed\n";
|
||||
return -1;
|
||||
}
|
||||
std::cout << "MonoTimeIsTimeoutReal() succeeded\n";
|
||||
|
||||
if (!run_test_MonoTimeCustomTime()) {
|
||||
std::cerr << "MonoTimeCustomTime() failed\n";
|
||||
return -1;
|
||||
}
|
||||
std::cout << "MonoTimeCustomTime() succeeded\n";
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user