Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[202205][ssg]: Use C++ strings for text handling #326

Merged
merged 1 commit into from
Apr 9, 2024
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
18 changes: 10 additions & 8 deletions src/systemd-sonic-generator/Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
CC=gcc
CFLAGS=-std=gnu99 -D_GNU_SOURCE

CPP=g++
CPPFLAGS=-std=c++11 -D_GNU_SOURCE
LFLAGS=-lpthread -lboost_filesystem -lboost_system -lgtest
CXX=g++
CXXFLAGS += -std=c++11 -D_GNU_SOURCE -I ./
LDFLAGS += -l stdc++ -lpthread -lboost_filesystem -lboost_system -lgtest

BINARY = systemd-sonic-generator
MAIN_TARGET = $(BINARY)_1.0.0_$(CONFIGURED_ARCH).deb
Expand All @@ -13,10 +13,10 @@ $(addprefix $(DEST)/, $(MAIN_TARGET)): $(DEST)/% :
mv ../$(MAIN_TARGET) $(DEST)/
rm ../$(BINARY)-* ../$(BINARY)_*

$(BINARY): systemd-sonic-generator.c
$(BINARY): systemd-sonic-generator.cpp
rm -f ./systemd-sonic-generator

$(CC) $(CFLAGS) -o $@ $^
$(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)

install: $(BINARY)
mkdir -p $(DESTDIR)
Expand All @@ -30,10 +30,12 @@ test: ssg_test
./ssg_test

ssg_test: ssg-test.cc systemd-sonic-generator.o
$(CPP) $(CPPFLAGS) -o $@ $^ $(LFLAGS)
$(CXX) $(CXXFLAGS) -ggdb -o $@ $^ $(LDFLAGS)

systemd-sonic-generator.o: systemd-sonic-generator.c
$(CC) $(CFLAGS) -D_SSG_UNITTEST -o $@ -c $^
systemd-sonic-generator.o: systemd-sonic-generator.cpp
$(CXX) $(CXXFLAGS) -ggdb -D_SSG_UNITTEST -o $@ -c $^

all: $(BINARY) test

clean:
rm -f ./systemd-sonic-generator
Expand Down
11 changes: 4 additions & 7 deletions src/systemd-sonic-generator/ssg-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,7 @@ class SsgMainTest : public SsgFunctionTest {

/* Find a string in a file */
bool find_string_in_file(std::string str,
std::string file_name,
int num_asics) {
std::string file_name) {
bool found = false;
std::string line;

Expand Down Expand Up @@ -214,7 +213,7 @@ class SsgMainTest : public SsgFunctionTest {
/* Run once for single instance */
finished = true;
}
EXPECT_EQ(find_string_in_file(str_t, target, num_asics),
EXPECT_EQ(find_string_in_file(str_t, target),
expected_result)
<< "Error validating " + str_t + " in " + target;
}
Expand Down Expand Up @@ -460,9 +459,8 @@ TEST_F(SsgFunctionTest, insert_instance_number) {
char input[] = "[email protected]";
for (int i = 0; i <= 100; ++i) {
std::string out = "test@" + std::to_string(i) + ".service";
char* ret = insert_instance_number(input, i);
ASSERT_NE(ret, nullptr);
EXPECT_STREQ(ret, out.c_str());
std::string ret = insert_instance_number(input, i);
EXPECT_EQ(ret, out);
}
}

Expand Down Expand Up @@ -513,7 +511,6 @@ TEST_F(SsgFunctionTest, get_unit_files) {

/* TEST ssg_main() argv error */
TEST_F(SsgMainTest, ssg_main_argv) {
FILE* fp;
std::vector<char*> argv_;
std::vector<std::string> arguments = {
"ssg_main",
Expand Down
Loading
Loading