From patchwork Wed Feb 28 14:17:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Sitnicki X-Patchwork-Id: 879153 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zryNj0jFLz9s31 for ; Thu, 1 Mar 2018 01:19:00 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id C3BF9F8C; Wed, 28 Feb 2018 14:17:28 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 8F399FA8 for ; Wed, 28 Feb 2018 14:17:25 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wm0-f67.google.com (mail-wm0-f67.google.com [74.125.82.67]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id C73A8110 for ; Wed, 28 Feb 2018 14:17:24 +0000 (UTC) Received: by mail-wm0-f67.google.com with SMTP id i3so3977086wmi.4 for ; Wed, 28 Feb 2018 06:17:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=kuOY8wpm/1xXbweXX9v2pACTrWmwbZWXLskYVAV7QzM=; b=k2P2hUNnEwJc3P9BFrwRjWTfvyYe0C7pLshxkZWtbqoh//07e+BKL8SL/mw0t7uRxp 8TXkFOoSErVERKkBPtXADUBN2cCmMDlmHDGqozxjHcj3sYVa22NqknbrMQhsY8jLkAhg Mzl100N0npk4jXZ7UJ9LCySMsOV4wrChgqCqd6obS8hf4YuocmfQcY4abwh9iv4C+U6/ pfwnqzKX1+ohGK2u70bVevJR99WmBXDv+gQ7vYB+kaa19drA3xHyF8sqLjCUHPDP8BdF EwyHAF2Y8NreUPC1kINO25teje9dseGZmXLU4dN0XMYbZ19pu/p2HT98eOEwrgjiY0kz 3udQ== X-Gm-Message-State: APf1xPBI02nSpTV2NKu80oyxwpfFQwTJNHTDmX4x1noLtw9FG4t8QvNc Hswirex9m5Dwmj8BQ2kJSrKTQw== X-Google-Smtp-Source: AG47ELszrMZdbF/oeremHsyTJMwY/ad5cHyjViwhMB0g+M8h1F90p1CO3YByz/Up4L3MQwzTqboYFw== X-Received: by 10.28.100.7 with SMTP id y7mr13021361wmb.122.1519827443403; Wed, 28 Feb 2018 06:17:23 -0800 (PST) Received: from redhat.com (88.red-2-136-197.dynamicip.rima-tde.net. [2.136.197.88]) by smtp.gmail.com with ESMTPSA id n64sm2141513wmd.11.2018.02.28.06.17.22 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 28 Feb 2018 06:17:22 -0800 (PST) From: Jakub Sitnicki To: Mark Michelson Date: Wed, 28 Feb 2018 15:17:15 +0100 Message-Id: <20180228141715.23882-4-jkbs@redhat.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180228141715.23882-1-jkbs@redhat.com> References: <20180220221332.2535-1-mmichels@redhat.com> <20180228141715.23882-1-jkbs@redhat.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: dev@openvswitch.org Subject: [ovs-dev] [PATCH 3/3] tests: Add tests for performance library module X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Check if performance module is calculating statistics as expected. Outputs that are currently not as expected have been annotated with FIXME. Signed-off-by: Jakub Sitnicki --- tests/automake.mk | 3 +- tests/library.at | 5 ++ tests/test-performance.c | 150 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 157 insertions(+), 1 deletion(-) create mode 100644 tests/test-performance.c -- 2.14.3 diff --git a/tests/automake.mk b/tests/automake.mk index 18698ebc3..f7ef68059 100644 --- a/tests/automake.mk +++ b/tests/automake.mk @@ -364,7 +364,8 @@ tests_ovstest_SOURCES = \ tests/test-uuid.c \ tests/test-bitmap.c \ tests/test-vconn.c \ - tests/test-aa.c + tests/test-aa.c \ + tests/test-performance.c if !WIN32 tests_ovstest_SOURCES += \ diff --git a/tests/library.at b/tests/library.at index 5efbfbb7c..dc6631376 100644 --- a/tests/library.at +++ b/tests/library.at @@ -251,3 +251,8 @@ AT_CLEANUP AT_SETUP([rcu]) AT_CHECK([ovstest test-rcu-quiesce], [0], []) AT_CLEANUP + +AT_SETUP([performance module]) +AT_CHECK([ovstest test-performance], [0], [.... +], [ignore]) +AT_CLEANUP diff --git a/tests/test-performance.c b/tests/test-performance.c new file mode 100644 index 000000000..b5659dc32 --- /dev/null +++ b/tests/test-performance.c @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2018 Red Hat, Inc. + * + * 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 +#undef NDEBUG +#include "performance.h" +#include +#include +#include +#include "ovstest.h" +#include "util.h" + +#define MAX_SAMPLES 100 +#define UNIT PERF_MS + +struct test_data { + const char *name; + unsigned long long samples[MAX_SAMPLES]; + size_t num_samples; + struct performance_stats expected_stats; +}; + +struct test_data data_sets[] = { + { + .name = "1-interval-zero-length", + .samples = { 1, 1 }, /* FIXME: First sample can't be 0. */ + .num_samples = 2, + .expected_stats = { + .count = 1, + .max = 0, + .min = 0, + .pctl_95 = 0, + .ewma_50 = 0, + .ewma_1 = 0, + }, + }, + { + .name = "1-interval-unit-length", + /* FIXME: First sample can't be 0. */ + .samples = { 1, 2 }, + .num_samples = 2, + .expected_stats = { + .count = 1, + .max = 1, + .min = 0, /* FIXME: min should be 1. */ + .pctl_95 = 0, + .ewma_50 = 1, + .ewma_1 = 1, + }, + }, + { + .name = "10-intervals-unit-length", + .samples = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }, + .num_samples = 11, + .expected_stats = { + .count = 10, + .max = 1, + .min = 0, /* FIXME: min should be 1. */ + .pctl_95 = 1, + .ewma_50 = 1, + .ewma_1 = 1, + }, + }, + { + .name = "10-intervals-linear-growth", + .samples = { 1, 2, 4, 7, 11, 16, 22, 29, 37, 46, 56 }, + .num_samples = 11, + .expected_stats = { + .count = 10, + .max = 10, + .min = 0, /* FIXME: min should be 1. */ + .pctl_95 = 5.8, /* FIXME: 95th percentile should be close to 10. */ + .ewma_50 = 9.0, + .ewma_1 = 1.4, + }, + }, +}; + +#define ASSERT_MSG(COND, MSG, ...) \ + if (!(COND)) { \ + fprintf(stderr, MSG "\n", ##__VA_ARGS__); \ + assert(COND); \ + } + +#define ASSERT_ULL_EQ(a, b) \ + ASSERT_MSG(a == b, \ + "Assertion '%s == %s' failed: %llu == %llu", \ + #a, #b, a, b) + +#define ASSERT_DOUBLE_EQ(a, b, eps) \ + ASSERT_MSG(fabs(a - b) < eps, \ + "Assertion '|%s - %s| < %s' failed: |%g - %g| < %g", \ + #a, #b, #eps, a, b, eps) + +#define ASSERT_STATS_EQ(a, b) \ + do { \ + ASSERT_ULL_EQ((a)->count, (b)->count); \ + ASSERT_ULL_EQ((a)->max, (b)->max); \ + ASSERT_ULL_EQ((a)->min, (b)->min); \ + ASSERT_DOUBLE_EQ((a)->pctl_95, (b)->pctl_95, 1e-1); \ + ASSERT_DOUBLE_EQ((a)->ewma_50, (b)->ewma_50, 1e-1); \ + ASSERT_DOUBLE_EQ((a)->ewma_1, (b)->ewma_1, 1e-1); \ + } while (0) + +static void +test_performance_calculate_stats(void) +{ + struct test_data *d; + + for (size_t i = 0; i < ARRAY_SIZE(data_sets); i++) { + d = &data_sets[i]; + + fprintf(stderr, "TEST '%s'\n", d->name); + + performance_create(d->name, UNIT); + for (size_t j = 0; j < d->num_samples - 1; j ++) { + performance_start_sample(d->name, d->samples[j]); + performance_end_sample(d->name, d->samples[j + 1]); + } + performance_sync(); + + struct performance_stats stats = { 0 }; + performance_get_stats(d->name, &stats); + ASSERT_STATS_EQ(&stats, &d->expected_stats); + + printf("."); + } +} + +static void +test_performance_main(int argc OVS_UNUSED, char *argv[] OVS_UNUSED) +{ + test_performance_calculate_stats(); + printf("\n"); +} + +OVSTEST_REGISTER("test-performance", test_performance_main);