From 5860fdb9a9b26e37852520d4598749f65f893bb5 Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Mon, 21 Mar 2016 22:13:04 +0100 Subject: mos: add pseudo Mean Opinion Score routine thanks to Lorenzo Mangani for the original patch --- test/main.c | 1 + test/mos.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ test/srcs.mk | 1 + test/test.c | 7 +++++++ test/test.h | 12 ++++++++++++ 5 files changed, 74 insertions(+) create mode 100644 test/mos.c (limited to 'test') diff --git a/test/main.c b/test/main.c index 3a2cf37..9ee4825 100644 --- a/test/main.c +++ b/test/main.c @@ -26,6 +26,7 @@ static const struct test tests[] = { TEST(test_call_reject), TEST(test_cmd), TEST(test_cplusplus), + TEST(test_mos), TEST(test_ua_alloc), TEST(test_ua_register), TEST(test_uag_find_param), diff --git a/test/mos.c b/test/mos.c new file mode 100644 index 0000000..20b13c2 --- /dev/null +++ b/test/mos.c @@ -0,0 +1,53 @@ +/** + * @file test/mos.c Test the MOS (Mean Opinion Score) calculator + * + * Copyright (C) 2010 - 2016 Creytiv.com + */ +#include +#include +#include "test.h" + + +#define DEBUG_MODULE "mos" +#define DEBUG_LEVEL 5 +#include + + +int test_mos(void) +{ +#define PRECISION 0.001 + static struct { + /* input: */ + double rtt; + double jitter; + uint32_t packet_loss; + + /* output: */ + double r_factor; + double mos; + } testv[] = { + { 0.0, 0.0, 0, 92.95, 4.404 }, + { 500.0, 0.0, 0, 54.20, 2.796 }, + { 1000.0, 0.0, 0, 4.20, 0.990 }, + { 0.0, 100.0, 0, 84.20, 4.172 }, + { 0.0, 200.0, 0, 64.20, 3.315 }, + { 0.0, 0.0, 1, 90.45, 4.350 }, + { 0.0, 0.0, 10, 67.95, 3.499 }, + { 10.0, 10.0, 10, 67.20, 3.463 }, + }; + size_t i; + int err = 0; + + for (i=0; i #include #include #include "test.h" @@ -35,3 +36,9 @@ int re_main_timeout(uint32_t timeout_ms) tmr_cancel(&tmr); return err; } + + +bool test_cmp_double(double a, double b, double precision) +{ + return fabs(a - b) < precision; +} diff --git a/test/test.h b/test/test.h index 4a91d28..20ccdcd 100644 --- a/test/test.h +++ b/test/test.h @@ -23,6 +23,16 @@ goto out; \ } +#define ASSERT_DOUBLE_EQ(expected, actual, prec) \ + if (!test_cmp_double((expected), (actual), (prec))) { \ + warning("selftest: ASSERT_DOUBLE_EQ: %s:%u:" \ + " expected=%f, actual=%f\n", \ + __FILE__, __LINE__, \ + (double)(expected), (double)(actual)); \ + err = EINVAL; \ + goto out; \ + } + #define ASSERT_STREQ(expected, actual) \ if (0 != str_cmp((expected), (actual))) { \ warning("selftest: ASSERT_STREQ: %s:%u:" \ @@ -47,6 +57,7 @@ /* helpers */ int re_main_timeout(uint32_t timeout_ms); +bool test_cmp_double(double a, double b, double precision); #ifdef USE_TLS @@ -78,6 +89,7 @@ int test_cmd(void); int test_ua_alloc(void); int test_uag_find_param(void); int test_ua_register(void); +int test_mos(void); int test_call_answer(void); int test_call_reject(void); -- cgit v1.2.3