Skip to content

Commit

Permalink
Added library unit tests to GitHub Actions
Browse files Browse the repository at this point in the history
The NanoLog library unit tests will now trigger whenever a push
or pull request is made. The tests will also no longer build by
default when invoking 'make' in the runtime directory. This should
help with issues such as issue #34 where users attempt to build
the library.
  • Loading branch information
syang0 committed Jul 19, 2020
1 parent f54a892 commit a67b683
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 34 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ jobs:
cd ${GITHUB_WORKSPACE}/preprocessor
python ./UnitTests.py
- name: Run Library Unit Tests
run: |
cd ${GITHUB_WORKSPACE}
git submodule update --init
cd runtime
make test -j2
# Excludes assert/death tests
./test --gtest_filter=-NanoLogTest.StagingBuffer_finishReservation_asserts:PackerTest.nibbler_assert
- name: Build Sample App
run: |
cd ${GITHUB_WORKSPACE}/sample
Expand Down
2 changes: 1 addition & 1 deletion runtime/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ifeq ($(PREPROCESSOR_NANOLOG),yes)
EXTRA_NANOLOG_FLAGS+=-DPREPROCESSOR_NANOLOG
endif

all: test Perf decompressor libNanoLog.a
all: decompressor libNanoLog.a

%.o:%.cc %.h
$(CXX) $(CXX_ARGS) $(EXTRA_NANOLOG_FLAGS) $(INCLUDES) -c $< -o $@
Expand Down
88 changes: 55 additions & 33 deletions runtime/LogTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1671,30 +1671,30 @@ TEST_F(LogTest, Decoder_internalDecompress_end2end) {
iFile.open(decomp);
ASSERT_TRUE(iFile.good());

const char* unorderedLines[] = {
"1969-12-31 16:00:01.000000090 testHelper/client.cc:20 NOTICE[5]: Simple log message with 0 parameters\r",
"1969-12-31 16:00:01.000000105 testHelper/client.cc:21 NOTICE[5]: This is a string aaaaaaaaaaaaaaa\r",
"1969-12-31 16:00:01.000000093 testHelper/client.cc:20 NOTICE[10]: Simple log message with 0 parameters\r",
"1969-12-31 16:00:01.000000096 testHelper/client.cc:21 NOTICE[10]: This is a string aaaaaaaaaaaaaaa\r",
"1969-12-31 16:00:01.000000100 testHelper/client.cc:20 NOTICE[10]: Simple log message with 0 parameters\r",
"1969-12-31 16:00:01.000000111 testHelper/client.cc:21 NOTICE[10]: This is a string aaaaaaaaaaaaaaa\r",
"1969-12-31 16:00:01.000000145 testHelper/client.cc:20 NOTICE[5]: Simple log message with 0 parameters\r",
"1969-12-31 16:00:01.000000156 testHelper/client.cc:21 NOTICE[5]: This is a string aaaaaaaaaaaaaaa\r",
"1969-12-31 16:00:01.000000118 testHelper/client.cc:20 NOTICE[10]: Simple log message with 0 parameters\r",
"1969-12-31 16:00:01.000000091 testHelper/client.cc:20 NOTICE[11]: Simple log message with 0 parameters\r",
"1969-12-31 16:00:01.000000135 testHelper/client.cc:20 NOTICE[12]: Simple log message with 0 parameters\r",
"1969-12-31 16:00:01.000000126 testHelper/client.cc:20 NOTICE[7]: Simple log message with 0 parameters\r"
};

std::string iLine;
for (const char *line : unorderedLines) {
std::vector<std::string> iLines;
for (int i = 0; i < 12; ++i) {
ASSERT_TRUE(iFile.good());
std::string iLine;
std::getline(iFile, iLine);
EXPECT_STREQ(line, iLine.c_str());
iLines.push_back(iLine.c_str() + 14); // +14 to skip date and hour
}

EXPECT_FALSE(iFile.eof());
iFile.close();

EXPECT_STREQ(iLines[0].c_str(), "00:01.000000090 testHelper/client.cc:20 NOTICE[5]: Simple log message with 0 parameters\r");
EXPECT_STREQ(iLines[1].c_str(), "00:01.000000105 testHelper/client.cc:21 NOTICE[5]: This is a string aaaaaaaaaaaaaaa\r");
EXPECT_STREQ(iLines[2].c_str(), "00:01.000000093 testHelper/client.cc:20 NOTICE[10]: Simple log message with 0 parameters\r");
EXPECT_STREQ(iLines[3].c_str(), "00:01.000000096 testHelper/client.cc:21 NOTICE[10]: This is a string aaaaaaaaaaaaaaa\r");
EXPECT_STREQ(iLines[4].c_str(), "00:01.000000100 testHelper/client.cc:20 NOTICE[10]: Simple log message with 0 parameters\r");
EXPECT_STREQ(iLines[5].c_str(), "00:01.000000111 testHelper/client.cc:21 NOTICE[10]: This is a string aaaaaaaaaaaaaaa\r");
EXPECT_STREQ(iLines[6].c_str(), "00:01.000000145 testHelper/client.cc:20 NOTICE[5]: Simple log message with 0 parameters\r");
EXPECT_STREQ(iLines[7].c_str(), "00:01.000000156 testHelper/client.cc:21 NOTICE[5]: This is a string aaaaaaaaaaaaaaa\r");
EXPECT_STREQ(iLines[8].c_str(), "00:01.000000118 testHelper/client.cc:20 NOTICE[10]: Simple log message with 0 parameters\r");
EXPECT_STREQ(iLines[9].c_str(), "00:01.000000091 testHelper/client.cc:20 NOTICE[11]: Simple log message with 0 parameters\r");
EXPECT_STREQ(iLines[10].c_str(), "00:01.000000135 testHelper/client.cc:20 NOTICE[12]: Simple log message with 0 parameters\r");
EXPECT_STREQ(iLines[11].c_str(), "00:01.000000126 testHelper/client.cc:20 NOTICE[7]: Simple log message with 0 parameters\r");

// try iterative interface
LogMessage msg;
ASSERT_TRUE(dc.open(testFile));
Expand All @@ -1710,11 +1710,27 @@ TEST_F(LogTest, Decoder_internalDecompress_end2end) {
iFile.open(decomp);
ASSERT_TRUE(iFile.good());

for (const char *line : unorderedLines) {
iLines.clear();
for (int i = 0; i < 12; ++i) {
ASSERT_TRUE(iFile.good());
std::string iLine;
std::getline(iFile, iLine);
EXPECT_STREQ(line, iLine.c_str());
iLines.push_back(iLine.c_str() + 14); // +14 to skip date and hour
}

EXPECT_STREQ(iLines[0].c_str(), "00:01.000000090 testHelper/client.cc:20 NOTICE[5]: Simple log message with 0 parameters\r");
EXPECT_STREQ(iLines[1].c_str(), "00:01.000000105 testHelper/client.cc:21 NOTICE[5]: This is a string aaaaaaaaaaaaaaa\r");
EXPECT_STREQ(iLines[2].c_str(), "00:01.000000093 testHelper/client.cc:20 NOTICE[10]: Simple log message with 0 parameters\r");
EXPECT_STREQ(iLines[3].c_str(), "00:01.000000096 testHelper/client.cc:21 NOTICE[10]: This is a string aaaaaaaaaaaaaaa\r");
EXPECT_STREQ(iLines[4].c_str(), "00:01.000000100 testHelper/client.cc:20 NOTICE[10]: Simple log message with 0 parameters\r");
EXPECT_STREQ(iLines[5].c_str(), "00:01.000000111 testHelper/client.cc:21 NOTICE[10]: This is a string aaaaaaaaaaaaaaa\r");
EXPECT_STREQ(iLines[6].c_str(), "00:01.000000145 testHelper/client.cc:20 NOTICE[5]: Simple log message with 0 parameters\r");
EXPECT_STREQ(iLines[7].c_str(), "00:01.000000156 testHelper/client.cc:21 NOTICE[5]: This is a string aaaaaaaaaaaaaaa\r");
EXPECT_STREQ(iLines[8].c_str(), "00:01.000000118 testHelper/client.cc:20 NOTICE[10]: Simple log message with 0 parameters\r");
EXPECT_STREQ(iLines[9].c_str(), "00:01.000000091 testHelper/client.cc:20 NOTICE[11]: Simple log message with 0 parameters\r");
EXPECT_STREQ(iLines[10].c_str(), "00:01.000000135 testHelper/client.cc:20 NOTICE[12]: Simple log message with 0 parameters\r");
EXPECT_STREQ(iLines[11].c_str(), "00:01.000000126 testHelper/client.cc:20 NOTICE[7]: Simple log message with 0 parameters\r");

EXPECT_FALSE(iFile.eof());
iFile.close();

Expand Down Expand Up @@ -1744,11 +1760,12 @@ TEST_F(LogTest, Decoder_internalDecompress_end2end) {
"1969-12-31 16:00:01.000000156 testHelper/client.cc:21 NOTICE[5]: This is a string aaaaaaaaaaaaaaa\r"
};

std::string iLine;
iFile.open(decomp);
for (const char *line : orderedLines) {
ASSERT_TRUE(iFile.good());
std::getline(iFile, iLine);
EXPECT_STREQ(line, iLine.c_str());
EXPECT_STREQ(line + 14, iLine.c_str() + 14); // +14 to skip date
}
EXPECT_FALSE(iFile.eof());
iFile.close();
Expand Down Expand Up @@ -1860,7 +1877,8 @@ TEST_F(LogTest, Decoder_internalDecompress_fileBreaks) {
for (const char *line : expectedLines) {
ASSERT_TRUE(iFile.good());
std::getline(iFile, iLine);
EXPECT_STREQ(line, iLine.c_str());
if (iLine.size() >= 14)
EXPECT_STREQ(line + 14, iLine.c_str() + 14);// +14 skips date + hour
}
EXPECT_FALSE(iFile.eof());
iFile.close();
Expand All @@ -1881,7 +1899,8 @@ TEST_F(LogTest, Decoder_internalDecompress_fileBreaks) {
for (const char *line : expectedLines) {
ASSERT_TRUE(iFile.good());
std::getline(iFile, iLine);
EXPECT_STREQ(line, iLine.c_str());
if (iLine.size() >= 14)
EXPECT_STREQ(line + 14, iLine.c_str() + 14);// +14 skips date + hour
}
EXPECT_FALSE(iFile.eof());
iFile.close();
Expand All @@ -1901,7 +1920,8 @@ TEST_F(LogTest, Decoder_internalDecompress_fileBreaks) {
for (const char *line : expectedLines) {
ASSERT_TRUE(iFile.good());
std::getline(iFile, iLine);
EXPECT_STREQ(line, iLine.c_str());
if (iLine.size() >= 14)
EXPECT_STREQ(line + 14, iLine.c_str() + 14);// +14 skips date + hour
}
EXPECT_FALSE(iFile.eof());
iFile.close();
Expand Down Expand Up @@ -1978,7 +1998,7 @@ TEST_F(LogTest, Decoder_internalDecompress_fileBreaks2) {
1,
false,
&compressedLogs);
EXPECT_EQ(1, compressedLogs);
EXPECT_EQ(6, compressedLogs);
EXPECT_EQ(1*sizeof(UncompressedEntry), bytesRead);
oFile.write(outputBuffer, encoder3.getEncodedBytes());
oFile.close();
Expand Down Expand Up @@ -2014,7 +2034,8 @@ TEST_F(LogTest, Decoder_internalDecompress_fileBreaks2) {
for (const char *line : expectedLines) {
ASSERT_TRUE(iFile.good());
std::getline(iFile, iLine);
EXPECT_STREQ(line, iLine.c_str());
if (iLine.size() >= 14)
EXPECT_STREQ(line + 14, iLine.c_str() + 14);// +14 skips date + hour
}
EXPECT_FALSE(iFile.eof());
iFile.close();
Expand Down Expand Up @@ -2079,7 +2100,8 @@ TEST_F(LogTest, Decoder_decompressNextLogStatement_timeTravel) {
for (const char *line : expectedLines) {
ASSERT_TRUE(iFile.good());
std::getline(iFile, iLine);
EXPECT_STREQ(line, iLine.c_str());
if (iLine.size() >= 14)
EXPECT_STREQ(line + 14, iLine.c_str() + 14);// +14 skips date + hour
}
EXPECT_FALSE(iFile.eof());
iFile.close();
Expand All @@ -2099,7 +2121,8 @@ TEST_F(LogTest, Decoder_decompressNextLogStatement_timeTravel) {
for (const char *line : expectedLines) {
ASSERT_TRUE(iFile.good());
std::getline(iFile, iLine);
EXPECT_STREQ(line, iLine.c_str());
if (iLine.size() >= 14)
EXPECT_STREQ(line + 14, iLine.c_str() + 14);// +14 skips date + hour
}
EXPECT_FALSE(iFile.eof());
iFile.close();
Expand All @@ -2119,7 +2142,8 @@ TEST_F(LogTest, Decoder_decompressNextLogStatement_timeTravel) {
for (const char *line : expectedLines) {
ASSERT_TRUE(iFile.good());
std::getline(iFile, iLine);
EXPECT_STREQ(line, iLine.c_str());
if (iLine.size() >= 14)
EXPECT_STREQ(line + 14, iLine.c_str() + 14);// +14 skips date + hour
}
EXPECT_FALSE(iFile.eof());
iFile.close();
Expand Down Expand Up @@ -2243,7 +2267,8 @@ TEST_F(LogTest, Decoder_getNextLogStatement) {
for (const char *line : expectedLines) {
ASSERT_TRUE(iFile.good());
std::getline(iFile, iLine);
EXPECT_STREQ(line, iLine.c_str());
if (iLine.size() >= 14)
EXPECT_STREQ(line + 14, iLine.c_str() + 14);// +14 skips date + hour
}
EXPECT_FALSE(iFile.eof());
iFile.close();
Expand Down Expand Up @@ -2301,9 +2326,6 @@ TEST_F(LogTest, Decoder_getNextLogStatement) {

std::remove(testFile);
std::remove(decomp);



}

// Static helper functions to test when aggregation is run.
Expand Down
24 changes: 24 additions & 0 deletions runtime/PackerTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,30 @@ TEST_F(PackerTest, nibbler) {
EXPECT_EQ(int64_t(-(1LL<<48)), nb.getNext<int64_t>());
EXPECT_EQ(int64_t(-(1LL<<56)), nb.getNext<int64_t>());

}

TEST_F(PackerTest, nibbler_assert) {
BufferUtils::TwoNibbles nibbles[1000];
char backing_buffer[1024];
char *buffer = backing_buffer;

// Start packing some data
int nibbleCntr = 0;
nibbles[nibbleCntr++/2].first = pack(&buffer, (float)(0.1));
nibbles[nibbleCntr++/2].second = pack(&buffer, (double)(0.2));

// Now let's squash the nibbles and pack()-ed values into one stream.
uint32_t packedBytes = buffer - backing_buffer;
uint32_t nibbleBytes = (nibbleCntr+1)/2;

memmove(backing_buffer + nibbleBytes, backing_buffer, packedBytes);
memcpy(backing_buffer, nibbles, nibbleBytes);

Nibbler nb(backing_buffer, nibbleCntr);

// Consume all the data and prepare for death
EXPECT_EQ((float)0.1, nb.getNext<float>());
EXPECT_EQ((double)0.2, nb.getNext<double>());
EXPECT_DEATH(nb.getNext<int>(), "");
}

Expand Down

0 comments on commit a67b683

Please sign in to comment.