Compare commits
10 Commits
good_maste
...
4ebffd8c63
Author | SHA1 | Date | |
---|---|---|---|
4ebffd8c63 | |||
8923e09b36 | |||
ec4195f18a | |||
062ad7ae80 | |||
aad07611c7 | |||
0dcb66f143 | |||
331c25b0e6 | |||
e50844be06 | |||
4dd7c98c1a | |||
63bad2e99a |
42
.github/workflows/cd.yml
vendored
42
.github/workflows/cd.yml
vendored
@ -13,7 +13,7 @@ jobs:
|
|||||||
windows:
|
windows:
|
||||||
timeout-minutes: 15
|
timeout-minutes: 15
|
||||||
|
|
||||||
runs-on: windows-latest
|
runs-on: windows-2019
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
@ -34,10 +34,50 @@ jobs:
|
|||||||
- name: Build
|
- name: Build
|
||||||
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4
|
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
|
- uses: actions/upload-artifact@v3
|
||||||
|
if: success() || failure()
|
||||||
with:
|
with:
|
||||||
name: ${{ github.event.repository.name }}-windows-msvc-x86_64
|
name: ${{ github.event.repository.name }}-windows-msvc-x86_64
|
||||||
# TODO: do propper packing
|
# TODO: do propper packing
|
||||||
path: |
|
path: |
|
||||||
${{github.workspace}}/build/bin/
|
${{github.workspace}}/build/bin/
|
||||||
|
|
||||||
|
windows-asan:
|
||||||
|
timeout-minutes: 15
|
||||||
|
|
||||||
|
runs-on: windows-2019
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
submodules: recursive
|
||||||
|
|
||||||
|
- name: Install Dependencies
|
||||||
|
run: vcpkg install libsodium:x64-windows-static pthreads:x64-windows-static
|
||||||
|
|
||||||
|
# setup vs env
|
||||||
|
- uses: ilammy/msvc-dev-cmd@v1
|
||||||
|
with:
|
||||||
|
arch: amd64
|
||||||
|
|
||||||
|
- name: Configure CMake
|
||||||
|
run: cmake -G Ninja -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static -DTOMATO_ASAN=ON -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded
|
||||||
|
|
||||||
|
- 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
|
||||||
|
if: success() || failure()
|
||||||
|
with:
|
||||||
|
name: ${{ github.event.repository.name }}-windows-msvc-asan-x86_64
|
||||||
|
# TODO: do propper packing
|
||||||
|
# TODO: also switch to asan dlls
|
||||||
|
path: |
|
||||||
|
${{github.workspace}}/build/bin/
|
||||||
|
|
||||||
|
6
.github/workflows/ci.yml
vendored
6
.github/workflows/ci.yml
vendored
@ -29,6 +29,9 @@ jobs:
|
|||||||
- name: Build
|
- name: Build
|
||||||
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4
|
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4
|
||||||
|
|
||||||
|
- name: temp test
|
||||||
|
run: ${{github.workspace}}/build/bin/mono_time_test
|
||||||
|
|
||||||
macos:
|
macos:
|
||||||
timeout-minutes: 10
|
timeout-minutes: 10
|
||||||
|
|
||||||
@ -72,3 +75,6 @@ jobs:
|
|||||||
- name: Build
|
- name: Build
|
||||||
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4
|
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} -j 4
|
||||||
|
|
||||||
|
- name: temp test
|
||||||
|
run: ${{github.workspace}}/build/bin/mono_time_test.exe
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
|
cmake_minimum_required(VERSION 3.14...3.24 FATAL_ERROR)
|
||||||
|
|
||||||
# cmake setup begin
|
# cmake setup begin
|
||||||
project(tomato)
|
project(tomato)
|
||||||
@ -18,6 +18,26 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
|
|||||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
|
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
|
||||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
|
||||||
|
|
||||||
|
option(TOMATO_ASAN "Build tomato with asan (gcc/clang/msvc)" OFF)
|
||||||
|
|
||||||
|
if (TOMATO_ASAN)
|
||||||
|
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
|
||||||
|
if (NOT WIN32) # exclude mingw
|
||||||
|
link_libraries(-fsanitize=address)
|
||||||
|
#link_libraries(-fsanitize=address,undefined)
|
||||||
|
#link_libraries(-fsanitize=undefined)
|
||||||
|
message("II enabled ASAN")
|
||||||
|
else()
|
||||||
|
message("!! can not enable ASAN on this platform (gcc/clang + win)")
|
||||||
|
endif()
|
||||||
|
elseif (MSVC)
|
||||||
|
add_compile_options("/fsanitize=address")
|
||||||
|
message("II enabled ASAN")
|
||||||
|
else()
|
||||||
|
message("!! can not enable ASAN on this platform")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
# external libs
|
# external libs
|
||||||
add_subdirectory(./external) # before increasing warn levels, sad :(
|
add_subdirectory(./external) # before increasing warn levels, sad :(
|
||||||
|
|
||||||
@ -33,13 +53,8 @@ if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL
|
|||||||
#-Wsign-conversion # Warn on sign conversions
|
#-Wsign-conversion # Warn on sign conversions
|
||||||
-Wshadow # Warn if a variable declaration shadows one from a parent context
|
-Wshadow # Warn if a variable declaration shadows one from a parent context
|
||||||
)
|
)
|
||||||
|
|
||||||
if (NOT WIN32)
|
|
||||||
#link_libraries(-fsanitize=address,undefined)
|
|
||||||
#link_libraries(-fsanitize=undefined)
|
|
||||||
endif()
|
|
||||||
elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC")
|
elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC")
|
||||||
if (CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
|
if (MSVC)
|
||||||
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||||
else()
|
else()
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
|
||||||
|
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.h
|
||||||
${TOX_DIR}testing/misc_tools.c
|
${TOX_DIR}testing/misc_tools.c
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(DHT_Bootstrap toxcore)
|
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::cerr << "MonoTimeUnixTimeIncreasesOverTime() succeeded\n";
|
||||||
|
|
||||||
|
if (!run_test_MonoTimeIsTimeout()) {
|
||||||
|
std::cerr << "MonoTimeIsTimeout() failed\n";
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
std::cerr << "MonoTimeIsTimeout() succeeded\n";
|
||||||
|
|
||||||
|
if (!run_test_MonoTimeIsTimeoutReal()) {
|
||||||
|
std::cerr << "MonoTimeIsTimeoutReal() failed\n";
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
std::cerr << "MonoTimeIsTimeoutReal() succeeded\n";
|
||||||
|
|
||||||
|
if (!run_test_MonoTimeCustomTime()) {
|
||||||
|
std::cerr << "MonoTimeCustomTime() failed\n";
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
std::cerr << "MonoTimeCustomTime() succeeded\n";
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
Reference in New Issue
Block a user