Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,6 @@ if(ENABLE_DOCS)
find_program(PipEnv pipenv REQUIRED)
endif()

# Catch2 for tests
set(CATCH_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/lib/catch2)

include(CTest)
set(TS_HAS_TESTS ${BUILD_REGRESSION_TESTING})

Expand Down
23 changes: 23 additions & 0 deletions proxy/hdrs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,26 @@ target_link_libraries(hdrs
PRIVATE
ts::inkevent
)

add_executable(test_proxy_hdrs
unit_tests/test_HdrHeap.cc
unit_tests/test_Hdrs.cc
unit_tests/test_HdrUtils.cc
unit_tests/test_HdrHeap.cc
unit_tests/test_HeaderValidator.cc
unit_tests/test_Huffmancode.cc
unit_tests/test_mime.cc
unit_tests/test_URL.cc
unit_tests/unit_test_main.cc
)
target_link_libraries(test_proxy_hdrs PRIVATE ts::hdrs ts::tscore ts::inkevent catch2::catch2)
add_test(NAME test_proxy_hdrs COMMAND test_proxy_hdrs)

add_executable(test_proxy_hdrs_xpack
XPACK.cc
HuffmanCodec.cc
unit_tests/test_XPACK.cc
)
target_include_directories(test_proxy_hdrs_xpack PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(test_proxy_hdrs_xpack PRIVATE ts::tscore libswoc catch2::catch2)
Copy link
Contributor

@JosiahWI JosiahWI Aug 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also depends on tscpputil. Doesn't depend on libswoc (that I can find).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tscore needs libswoc but doesn't have it PUBLIC

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It almost certainly should be PUBLIC.

add_test(NAME test_proxy_hdrs_xpack COMMAND test_proxy_hdrs_xpack)
11 changes: 1 addition & 10 deletions proxy/hdrs/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ load_http_hdr_LDADD =
check_PROGRAMS = \
test_proxy_hdrs \
test_hdr_heap \
test_Huffmancode \
test_XPACK

TESTS = $(check_PROGRAMS)
Expand All @@ -83,6 +82,7 @@ test_proxy_hdrs_SOURCES = \
unit_tests/test_HdrUtils.cc \
unit_tests/test_URL.cc \
unit_tests/test_mime.cc \
unit_tests/test_Huffmancode.cc \
unit_tests/test_HeaderValidator.cc

test_proxy_hdrs_LDFLAGS = @AM_LDFLAGS@ @SWOC_LDFLAGS@ @YAMLCPP_LDFLAGS@ @OPENSSL_LDFLAGS@
Expand Down Expand Up @@ -112,15 +112,6 @@ test_hdr_heap_LDADD = \
@SWOC_LIBS@ @HWLOC_LIBS@ \
@LIBPCRE@ @OPENSSL_LIBS@ @LIBCAP@

test_Huffmancode_LDADD = \
$(top_builddir)/src/tscore/libtscore.a \
$(top_builddir)/src/tscpp/util/libtscpputil.la

test_Huffmancode_SOURCES = \
test_Huffmancode.cc \
HuffmanCodec.cc \
HuffmanCodec.h

test_XPACK_CPPFLAGS = \
$(AM_CPPFLAGS) \
-I$(abs_top_srcdir)/lib/catch2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <iostream>
#include <cassert>
#include <cstring>
#include "catch.hpp"

using namespace std;

Expand Down Expand Up @@ -88,13 +89,20 @@ random_test()
free(dst_start);
}

TEST_CASE("Huffmancode Random", "[proxy][huffman]")
{
// This doesn't check anything ...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then why does it exist?

for (int i = 0; i < 100; i++) {
random_test();
}
}

union Value {
uint32_t x;
uint8_t y[4];
};

void
values_test()
TEST_CASE("values_test", "[proxy][huffman]")
{
char dst_start[4];
int size = sizeof(test_values) / 4;
Expand Down Expand Up @@ -139,11 +147,11 @@ values_test()

// EOS is treated as invalid so check for an error
if (value == 0x3fffffff) {
assert(bytes == -1);
REQUIRE(bytes == -1);
continue;
}
assert(dst_start[0] == ascii_value);
assert(bytes == 1);
REQUIRE(dst_start[0] == ascii_value);
REQUIRE(bytes == 1);
}
}

Expand All @@ -164,22 +172,20 @@ const static struct {
17 }
};

void
encode_test()
TEST_CASE("encode_test", "[proxy][huffman]")
{
for (const auto &i : huffman_encode_test_data) {
uint8_t *dst = static_cast<uint8_t *>(malloc(i.expect_len));
int64_t encoded_len = huffman_encode(dst, i.src, i.src_len);

assert(encoded_len == i.expect_len);
assert(memcmp(i.expect, dst, encoded_len) == 0);
REQUIRE(encoded_len == i.expect_len);
REQUIRE(memcmp(i.expect, dst, encoded_len) == 0);

free(dst);
}
}

void
decode_errors_test()
TEST_CASE("decode_errors", "[proxy][huffman]")
{
const static struct {
char *input;
Expand All @@ -196,24 +202,7 @@ decode_errors_test()
int dst_len = 2 * test_cases[i].input_len;
char *dst = (char *)malloc(dst_len);
int len = huffman_decode(dst, (uint8_t *)test_cases[i].input, test_cases[i].input_len);
assert(len == -1);
REQUIRE(len == -1);
free(dst);
}
}

int
main()
{
hpack_huffman_init();

for (int i = 0; i < 100; i++) {
random_test();
}
values_test();
decode_errors_test();

hpack_huffman_fin();

encode_test();
return 0;
}
3 changes: 3 additions & 0 deletions proxy/hdrs/unit_tests/unit_test_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/

#include "HTTP.h"
#include "HuffmanCodec.h"

#define CATCH_CONFIG_RUNNER
#include "catch.hpp"
Expand All @@ -35,10 +36,12 @@ main(int argc, char *argv[])
cmd_disable_pfreelist = true;
// Get all of the HTTP WKS items populated.
http_init();
hpack_huffman_init();

int result = Catch::Session().run(argc, argv);

// global clean-up...
hpack_huffman_fin();

return result;
}
4 changes: 2 additions & 2 deletions src/api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ add_executable(test_Metrics
test_Metrics.cc
)

target_link_libraries(test_Metrics PRIVATE tsapi tscore)
target_include_directories(test_Metrics PRIVATE ${CMAKE_SOURCE_DIR}/include ${CATCH_INCLUDE_DIR})
target_link_libraries(test_Metrics PRIVATE tsapi tscore catch2::catch2)
target_include_directories(test_Metrics PRIVATE ${CMAKE_SOURCE_DIR}/include)

add_test(NAME test_Metrics COMMAND $<TARGET_FILE:test_Metrics>)
2 changes: 1 addition & 1 deletion src/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
include_directories(
${IOCORE_INCLUDE_DIRS}
${PROXY_INCLUDE_DIRS}
${CATCH_INCLUDE_DIR}
)

link_libraries(
Expand Down Expand Up @@ -55,6 +54,7 @@ link_libraries(
inkevent
yaml-cpp
libswoc
catch2::catch2
)
if (TS_USE_LINUX_IO_URING)
link_libraries(inkuring uring)
Expand Down
6 changes: 5 additions & 1 deletion src/tscore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ target_link_libraries(tscore
if(TS_USE_POSIX_CAP)
target_link_libraries(tscore PUBLIC cap::cap)
endif()
if(TS_USE_HWLOC)
target_link_libraries(tscore PUBLIC hwloc::hwloc)
endif()

add_dependencies(tscore ParseRules)
target_include_directories(tscore PRIVATE
Expand Down Expand Up @@ -171,10 +174,11 @@ target_link_libraries(test_tscore
ts::tscpputil
OpenSSL::Crypto
OpenSSL::SSL
catch2::catch2
)
if(TS_USE_HWLOC)
target_link_libraries(test_tscore PRIVATE hwloc::hwloc)
endif()
target_include_directories(test_tscore PRIVATE ${CMAKE_SOURCE_DIR}/include ${CATCH_INCLUDE_DIR})
target_include_directories(test_tscore PRIVATE ${CMAKE_SOURCE_DIR}/include)

add_test(NAME test_tscore COMMAND $<TARGET_FILE:test_tscore>)
4 changes: 2 additions & 2 deletions src/tscpp/util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ add_executable(test_tscpputil
unit_tests/test_time_parser.cc
unit_tests/unit_test_main.cc
)
target_link_libraries(test_tscpputil PRIVATE tscpputil libswoc)
target_include_directories(test_tscpputil PRIVATE ${CMAKE_SOURCE_DIR}/include ${CATCH_INCLUDE_DIR})
target_link_libraries(test_tscpputil PRIVATE tscpputil libswoc catch2::catch2)
target_include_directories(test_tscpputil PRIVATE ${CMAKE_SOURCE_DIR}/include)

add_test(NAME test_tscpputil COMMAND $<TARGET_FILE:test_tscpputil>)