diff options
author | Harisuddin Mohamed Isa <harisuddin@gmail.com> | 2020-02-06 17:32:38 +0800 |
---|---|---|
committer | Matt Spinler <spinler@us.ibm.com> | 2020-02-07 16:02:00 +0000 |
commit | e2d1bf317c0ddf25ddd305aa8f3c6f09118f799c (patch) | |
tree | de330de70c2a62ce6785bca2dae1faee0f89a50e /test | |
parent | 6fd0c1e70c1f63c44ffa69308569b1be144451ce (diff) | |
download | phosphor-logging-e2d1bf317c0ddf25ddd305aa8f3c6f09118f799c.tar.gz phosphor-logging-e2d1bf317c0ddf25ddd305aa8f3c6f09118f799c.zip |
PEL: Print Failing MTMS section into JSON
Remove any trailing whitespace for serial number.
"Failing MTMS": {
"Section Version": "1",
"Sub-section type": "0",
"Created by": "0x4552",
"Machine Type Model": "OPWR-131",
"Serial Number": "1318ABA"
},
Testing: Manually run peltool and verified output. All unit tests
passed.
Signed-off-by: Harisuddin Mohamed Isa <harisuddin@gmail.com>
Change-Id: I7a05790bdf406ef6d7946ffae831a45ee6dd5cda
Diffstat (limited to 'test')
-rw-r--r-- | test/openpower-pels/Makefile.include | 10 | ||||
-rw-r--r-- | test/openpower-pels/json_utils_test.cpp | 50 |
2 files changed, 60 insertions, 0 deletions
diff --git a/test/openpower-pels/Makefile.include b/test/openpower-pels/Makefile.include index 2bed701..a700a50 100644 --- a/test/openpower-pels/Makefile.include +++ b/test/openpower-pels/Makefile.include @@ -9,6 +9,7 @@ check_PROGRAMS += \ fru_identity_test \ generic_section_test \ host_notifier_test \ + json_utils_test \ log_id_test \ mru_test \ mtms_test \ @@ -187,6 +188,7 @@ failing_mtms_test_CXXFLAGS = $(test_cxxflags) failing_mtms_test_LDADD = \ $(test_ldadd) \ $(top_builddir)/extensions/openpower-pels/failing_mtms.o \ + $(top_builddir)/extensions/openpower-pels/json_utils.o \ $(top_builddir)/extensions/openpower-pels/mtms.o failing_mtms_test_LDFLAGS = $(test_ldflags) @@ -343,3 +345,11 @@ host_notifier_test_LDADD = \ $(top_builddir)/extensions/openpower-pels/host_notifier.o \ $(top_builddir)/extensions/openpower-pels/repository.o host_notifier_test_LDFLAGS = $(test_ldflags) $(SDEVENTPLUS_LIBS) + +json_utils_test_SOURCES = %reldir%/json_utils_test.cpp +json_utils_test_CPPFLAGS = $(test_cppflags) +json_utils_test_CXXFLAGS = $(test_cxxflags) +json_utils_test_LDADD = \ + $(test_ldadd) \ + $(top_builddir)/extensions/openpower-pels/json_utils.o +json_utils_test_LDFLAGS = $(test_ldflags) diff --git a/test/openpower-pels/json_utils_test.cpp b/test/openpower-pels/json_utils_test.cpp new file mode 100644 index 0000000..60ca00d --- /dev/null +++ b/test/openpower-pels/json_utils_test.cpp @@ -0,0 +1,50 @@ +/** + * Copyright © 2019 IBM Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "extensions/openpower-pels/json_utils.hpp" + +#include <gtest/gtest.h> + +using namespace openpower::pels; + +TEST(JsonUtilsTest, TrimEndTest) +{ + std::string testStr("Test string 1"); + EXPECT_EQ(trimEnd(testStr), "Test string 1"); + testStr = "Test string 2 "; + EXPECT_EQ(trimEnd(testStr), "Test string 2"); + testStr = " Test string 3 "; + EXPECT_EQ(trimEnd(testStr), " Test string 3"); +} + +TEST(JsonUtilsTest, NumberToStringTest) +{ + size_t number = 123; + EXPECT_EQ(getNumberString("%d", number), "123"); + EXPECT_EQ(getNumberString("%03X", number), "07B"); + EXPECT_EQ(getNumberString("0x%X", number), "0x7B"); + ASSERT_EXIT((getNumberString("%123", number), exit(0)), + ::testing::KilledBySignal(SIGSEGV), ".*"); +} + +TEST(JsonUtilsTest, JsonInsertTest) +{ + std::string json; + jsonInsert(json, "Key", "Value1", 1); + EXPECT_EQ(json, " \"Key\": \"Value1\",\n"); + jsonInsert(json, "Keyxxxxxxxxxxxxxxxxxxxxxxxxxx", "Value2", 2); + EXPECT_EQ(json, " \"Key\": \"Value1\",\n" + " \"Keyxxxxxxxxxxxxxxxxxxxxxxxxxx\": \"Value2\",\n"); +} |