From: Pawel Tomaszewski Date: Wed, 26 Aug 2020 13:17:02 +0000 (+0100) Subject: intel_pmu 2.0 - unit tests X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=84f6676e87359ca47ea50e03e8327628973523d8;p=thirdparty%2Fcollectd.git intel_pmu 2.0 - unit tests Signed-off-by: Pawel Tomaszewski --- diff --git a/Makefile.am b/Makefile.am index 00b780c9f..effa6815e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1149,6 +1149,17 @@ intel_pmu_la_SOURCES = \ intel_pmu_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBJEVENTS_CPPFLAGS) intel_pmu_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBJEVENTS_LDFLAGS) intel_pmu_la_LIBADD = $(BUILD_WITH_LIBJEVENTS_LIBS) + +test_plugin_intel_pmu_SOURCES = \ + src/intel_pmu_test.c \ + src/utils/config_cores/config_cores.c \ + src/daemon/configfile.c \ + src/daemon/types_list.c +test_plugin_intel_pmu_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBJEVENTS_CPPFLAGS) +test_plugin_intel_pmu_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBJEVENTS_LDFLAGS) +test_plugin_intel_pmu_LDADD = libplugin_mock.la liboconfig.la $(BUILD_WITH_LIBJEVENTS_LIBS) +check_PROGRAMS += test_plugin_intel_pmu +TESTS += test_plugin_intel_pmu endif if BUILD_PLUGIN_INTEL_RDT diff --git a/src/intel_pmu_test.c b/src/intel_pmu_test.c new file mode 100644 index 000000000..7395f6596 --- /dev/null +++ b/src/intel_pmu_test.c @@ -0,0 +1,114 @@ +/** + * collectd - src/logparser_test.c + * + * Copyright(c) 2018 Intel Corporation. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + * Authors: + * Pawel Tomaszewski + **/ + +#include "intel_pmu.c" +#include "testing.h" + +// Helper functions +// static int ctx_entl_size = 0; + +intel_pmu_ctx_t* stub_pmu_init() { + intel_pmu_ctx_t* pmu_ctx = calloc(1, sizeof(*pmu_ctx)); + intel_pmu_entity_t* entl = calloc(1, sizeof(*entl)); + + pmu_ctx->entl = entl; + + return pmu_ctx; +} + +void stub_pmu_teardown(intel_pmu_ctx_t* pmu_ctx) { + free(pmu_ctx->entl); + free(pmu_ctx); +} + +DEF_TEST(pmu_config_hw_events__all_events) { + // setup + intel_pmu_ctx_t* pmu_ctx = stub_pmu_init(); + intel_pmu_entity_t* ent = pmu_ctx->entl; + + oconfig_value_t values[] = { + {.value.string = "All", .type = OCONFIG_TYPE_STRING}, + }; + oconfig_item_t config_item = { + .key = "HardwareEvents", + .values = values, + .values_num = STATIC_ARRAY_SIZE(values), + }; + + // check + int result = pmu_config_hw_events(&config_item, ent); + EXPECT_EQ_INT(0, result); + EXPECT_EQ_INT(1, ent->all_events); + + // cleanup + stub_pmu_teardown(pmu_ctx); + return 0; +} + +DEF_TEST(pmu_config_hw_events__few_events) { + // setup + intel_pmu_ctx_t* pmu_ctx = stub_pmu_init(); + intel_pmu_entity_t* ent = pmu_ctx->entl; + + oconfig_value_t values[] = { + {.value.string = "event0", .type = OCONFIG_TYPE_STRING}, + {.value.string = "event1", .type = OCONFIG_TYPE_STRING}, + {.value.string = "event2", .type = OCONFIG_TYPE_STRING}, + {.value.string = "event3", .type = OCONFIG_TYPE_STRING}, + {.value.string = "event4", .type = OCONFIG_TYPE_STRING} + }; + oconfig_item_t config_item = { + .key = "HardwareEvents", + .values = values, + .values_num = STATIC_ARRAY_SIZE(values), + }; + + // check + int result = pmu_config_hw_events(&config_item, ent); + EXPECT_EQ_INT(0, result); + EXPECT_EQ_INT(config_item.values_num, ent->hw_events_count); + for(int i = 0; i < ent->hw_events_count; i++) { + EXPECT_EQ_STR(values[i].value.string, ent->hw_events[i]); + } + + // cleanup + stub_pmu_teardown(pmu_ctx); + return 0; +} + +DEF_TEST(config_cores_parse) { + + return 0; +} + +int main(void) { + RUN_TEST(pmu_config_hw_events__all_events); + RUN_TEST(pmu_config_hw_events__few_events); + RUN_TEST(config_cores_parse); + + END_TEST; +} \ No newline at end of file