get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/26778/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 26778,
    "url": "http://patches.dpdk.org/api/patches/26778/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/1499782773-12277-5-git-send-email-harry.van.haaren@intel.com/",
    "project": {
        "id": 1,
        "url": "http://patches.dpdk.org/api/projects/1/?format=api",
        "name": "DPDK",
        "link_name": "dpdk",
        "list_id": "dev.dpdk.org",
        "list_email": "dev@dpdk.org",
        "web_url": "http://core.dpdk.org",
        "scm_url": "git://dpdk.org/dpdk",
        "webscm_url": "http://git.dpdk.org/dpdk",
        "list_archive_url": "https://inbox.dpdk.org/dev",
        "list_archive_url_format": "https://inbox.dpdk.org/dev/{}",
        "commit_url_format": ""
    },
    "msgid": "<1499782773-12277-5-git-send-email-harry.van.haaren@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1499782773-12277-5-git-send-email-harry.van.haaren@intel.com",
    "date": "2017-07-11T14:19:30",
    "name": "[dpdk-dev,v5,4/7] service cores: add unit tests",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": true,
    "hash": "8e318a840d8b297ffd236cc92e20e815dd6438ce",
    "submitter": {
        "id": 317,
        "url": "http://patches.dpdk.org/api/people/317/?format=api",
        "name": "Van Haaren, Harry",
        "email": "harry.van.haaren@intel.com"
    },
    "delegate": {
        "id": 1,
        "url": "http://patches.dpdk.org/api/users/1/?format=api",
        "username": "tmonjalo",
        "first_name": "Thomas",
        "last_name": "Monjalon",
        "email": "thomas@monjalon.net"
    },
    "mbox": "http://patches.dpdk.org/project/dpdk/patch/1499782773-12277-5-git-send-email-harry.van.haaren@intel.com/mbox/",
    "series": [],
    "comments": "http://patches.dpdk.org/api/patches/26778/comments/",
    "check": "fail",
    "checks": "http://patches.dpdk.org/api/patches/26778/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@dpdk.org",
        "Delivered-To": "patchwork@dpdk.org",
        "Received": [
            "from [92.243.14.124] (localhost [IPv6:::1])\n\tby dpdk.org (Postfix) with ESMTP id 3811F7CB4;\n\tTue, 11 Jul 2017 16:19:49 +0200 (CEST)",
            "from mga06.intel.com (mga06.intel.com [134.134.136.31])\n\tby dpdk.org (Postfix) with ESMTP id 15D14567E\n\tfor <dev@dpdk.org>; Tue, 11 Jul 2017 16:19:40 +0200 (CEST)",
            "from fmsmga005.fm.intel.com ([10.253.24.32])\n\tby orsmga104.jf.intel.com with ESMTP; 11 Jul 2017 07:19:40 -0700",
            "from silpixa00398672.ir.intel.com ([10.237.223.128])\n\tby fmsmga005.fm.intel.com with ESMTP; 11 Jul 2017 07:19:38 -0700"
        ],
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos;i=\"5.40,346,1496127600\"; d=\"scan'208\";a=\"125185201\"",
        "From": "Harry van Haaren <harry.van.haaren@intel.com>",
        "To": "dev@dpdk.org",
        "Cc": "thomas@monjalon.net, jerin.jacob@caviumnetworks.com,\n\tkeith.wiles@intel.com, bruce.richardson@intel.com,\n\tHarry van Haaren <harry.van.haaren@intel.com>",
        "Date": "Tue, 11 Jul 2017 15:19:30 +0100",
        "Message-Id": "<1499782773-12277-5-git-send-email-harry.van.haaren@intel.com>",
        "X-Mailer": "git-send-email 2.7.4",
        "In-Reply-To": "<1499782773-12277-1-git-send-email-harry.van.haaren@intel.com>",
        "References": "<1499445667-32588-1-git-send-email-harry.van.haaren@intel.com>\n\t<1499782773-12277-1-git-send-email-harry.van.haaren@intel.com>",
        "Subject": "[dpdk-dev] [PATCH v5 4/7] service cores: add unit tests",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.15",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<http://dpdk.org/ml/options/dev>,\n\t<mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://dpdk.org/ml/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<http://dpdk.org/ml/listinfo/dev>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>"
    },
    "content": "Add a bunch of unit tests, to ensure that the service\ncore functions are operating as expected.\n\nAs part of these tests a dummy service is registered which\nallows identifying if a service callback has been invoked\nby using the CPU tick counter. This allows identifying if\nfunctions to start and stop service lcores are actually having\neffect.\n\nSigned-off-by: Harry van Haaren <harry.van.haaren@intel.com>\nAcked-by: Jerin Jacob <jerin.jacob@caviumnetworks.com>\n\n---\n\nv5:\n- Improve unit test for dump() to enable and disable stats (Jerin)\n- Add new unit test for MT unsafe service callback (Harry)\n- Added Ack from ML\n\nv4:\n- Remove static slcore_id, make service-core choice dynamic (Jerin)\n- Use lcore_get_next() to acquire service cores (Jerin)\n- Improve unit test to ensure app can remote_launc() on a core that\n  previously served as a service-core (verifies ROLE_RTE is set) (Jerin)\n\nv2 changes;\n- Rename variable to slcore_id (Jerin)\n- Rename function to unregister_all() (Jerin)\n- Fix typos (Jerin)\n- Add unit test for get_by_name()\n- Add unit tests (all suggestions by Jerin)\n-- get_name()\n-- Verify probe_capability API\n-- Verify MT_SAFE capability (see code for details)\n-- Verify rte_service_dump() API\n---\n test/test/Makefile             |   2 +\n test/test/test_service_cores.c | 599 +++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 601 insertions(+)\n create mode 100644 test/test/test_service_cores.c",
    "diff": "diff --git a/test/test/Makefile b/test/test/Makefile\nindex e797c20..42d9a49 100644\n--- a/test/test/Makefile\n+++ b/test/test/Makefile\n@@ -151,6 +151,8 @@ SRCS-y += test_interrupts.c\n SRCS-y += test_version.c\n SRCS-y += test_func_reentrancy.c\n \n+SRCS-y += test_service_cores.c\n+\n SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += test_cmdline.c\n SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += test_cmdline_num.c\n SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += test_cmdline_etheraddr.c\ndiff --git a/test/test/test_service_cores.c b/test/test/test_service_cores.c\nnew file mode 100644\nindex 0000000..88fac8f\n--- /dev/null\n+++ b/test/test/test_service_cores.c\n@@ -0,0 +1,599 @@\n+/*-\n+ *   BSD LICENSE\n+ *\n+ *   Copyright(c) 2017 Intel Corporation. All rights reserved.\n+ *\n+ *   Redistribution and use in source and binary forms, with or without\n+ *   modification, are permitted provided that the following conditions\n+ *   are met:\n+ *\n+ *     * Redistributions of source code must retain the above copyright\n+ *       notice, this list of conditions and the following disclaimer.\n+ *     * Redistributions in binary form must reproduce the above copyright\n+ *       notice, this list of conditions and the following disclaimer in\n+ *       the documentation and/or other materials provided with the\n+ *       distribution.\n+ *     * Neither the name of Intel Corporation nor the names of its\n+ *       contributors may be used to endorse or promote products derived\n+ *       from this software without specific prior written permission.\n+ *\n+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n+ *   \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n+ */\n+\n+#include <rte_common.h>\n+#include <rte_hexdump.h>\n+#include <rte_mbuf.h>\n+#include <rte_malloc.h>\n+#include <rte_memcpy.h>\n+#include <rte_cycles.h>\n+\n+#include <rte_service.h>\n+#include <rte_service_component.h>\n+\n+#include \"test.h\"\n+\n+/* used as the service core ID */\n+static uint32_t slcore_id;\n+/* used as timestamp to detect if a service core is running */\n+static uint64_t service_tick;\n+/* used as a flag to check if a function was run */\n+static uint32_t service_remote_launch_flag;\n+\n+#define SERVICE_DELAY 1\n+\n+#define DUMMY_SERVICE_NAME \"dummy_service\"\n+#define MT_SAFE_SERVICE_NAME \"mt_safe_service\"\n+\n+static int\n+testsuite_setup(void)\n+{\n+\tslcore_id = rte_get_next_lcore(/* start core */ -1,\n+\t\t\t\t       /* skip master */ 1,\n+\t\t\t\t       /* wrap */ 0);\n+\n+\treturn TEST_SUCCESS;\n+}\n+\n+static void\n+testsuite_teardown(void)\n+{\n+\t/* release service cores? */\n+}\n+\n+static int32_t dummy_cb(void *args)\n+{\n+\tRTE_SET_USED(args);\n+\tservice_tick++;\n+\trte_delay_ms(SERVICE_DELAY);\n+\treturn 0;\n+}\n+\n+static int32_t dummy_mt_unsafe_cb(void *args)\n+{\n+\t/* before running test, the initialization has set pass_test to 1.\n+\t * If the cmpset in service-cores is working correctly, the code here\n+\t * should never fail to take the lock. If the lock *is* taken, fail the\n+\t * test, because two threads are concurrently in a non-MT safe callback.\n+\t */\n+\tuint32_t *test_params = args;\n+\tuint32_t *atomic_lock = &test_params[0];\n+\tuint32_t *pass_test = &test_params[1];\n+\tint lock_taken = rte_atomic32_cmpset(atomic_lock, 0, 1);\n+\tif (lock_taken) {\n+\t\t/* delay with the lock held */\n+\t\trte_delay_ms(250);\n+\t\trte_atomic32_clear((rte_atomic32_t *)atomic_lock);\n+\t} else {\n+\t\t/* 2nd thread will fail to take lock, so set pass flag */\n+\t\t*pass_test = 0;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+\n+static int32_t dummy_mt_safe_cb(void *args)\n+{\n+\t/* Atomic checks to ensure MT safe services allow > 1 thread to\n+\t * concurrently run the callback. The concept is as follows;\n+\t * 1) if lock is available, take the lock then delay\n+\t * 2) if first lock is taken, and a thread arrives in the CB, we know\n+\t *    that 2 threads are running the callback at the same time: MT safe\n+\t */\n+\tuint32_t *test_params = args;\n+\tuint32_t *atomic_lock = &test_params[0];\n+\tuint32_t *pass_test = &test_params[1];\n+\tint lock_taken = rte_atomic32_cmpset(atomic_lock, 0, 1);\n+\tif (lock_taken) {\n+\t\t/* delay with the lock held */\n+\t\trte_delay_ms(250);\n+\t\trte_atomic32_clear((rte_atomic32_t *)atomic_lock);\n+\t} else {\n+\t\t/* 2nd thread will fail to take lock, so set pass flag */\n+\t\t*pass_test = 1;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+/* unregister all services */\n+static int\n+unregister_all(void)\n+{\n+\tuint32_t i;\n+\tstruct rte_service_spec *dead = (struct rte_service_spec *)0xdead;\n+\n+\tTEST_ASSERT_EQUAL(-EINVAL, rte_service_unregister(0),\n+\t\t\t\"Unregistered NULL pointer\");\n+\tTEST_ASSERT_EQUAL(-EINVAL, rte_service_unregister(dead),\n+\t\t\t\"Unregistered invalid pointer\");\n+\n+\tuint32_t c = rte_service_get_count();\n+\tfor (i = 0; i < c; i++) {\n+\t\tstruct rte_service_spec *s = rte_service_get_by_id(i);\n+\t\tTEST_ASSERT_EQUAL(0, rte_service_unregister(s),\n+\t\t\t\t\"Error unregistering a valid service\");\n+\t}\n+\n+\trte_service_lcore_reset_all();\n+\n+\treturn TEST_SUCCESS;\n+}\n+\n+/* register a single dummy service */\n+static int\n+dummy_register(void)\n+{\n+\t/* make sure there are no remains from previous tests */\n+\tunregister_all();\n+\n+\tstruct rte_service_spec service;\n+\tmemset(&service, 0, sizeof(struct rte_service_spec));\n+\n+\tTEST_ASSERT_EQUAL(-EINVAL, rte_service_register(&service),\n+\t\t\t\"Invalid callback\");\n+\tservice.callback = dummy_cb;\n+\n+\tTEST_ASSERT_EQUAL(-EINVAL, rte_service_register(&service),\n+\t\t\t\"Invalid name\");\n+\tsnprintf(service.name, sizeof(service.name), DUMMY_SERVICE_NAME);\n+\n+\tTEST_ASSERT_EQUAL(0, rte_service_register(&service),\n+\t\t\t\"Failed to register valid service\");\n+\n+\treturn TEST_SUCCESS;\n+}\n+\n+/* verify get_by_name() service lookup */\n+static int\n+service_get_by_name(void)\n+{\n+\tunregister_all();\n+\n+\t/* ensure with no services registered returns NULL */\n+\tTEST_ASSERT_EQUAL(0, rte_service_get_by_name(DUMMY_SERVICE_NAME),\n+\t\t\t\"Service get by name should return NULL\");\n+\n+\t/* register service */\n+\tstruct rte_service_spec service;\n+\tmemset(&service, 0, sizeof(struct rte_service_spec));\n+\tTEST_ASSERT_EQUAL(-EINVAL, rte_service_register(&service),\n+\t\t\t\"Invalid callback\");\n+\tservice.callback = dummy_cb;\n+\tTEST_ASSERT_EQUAL(-EINVAL, rte_service_register(&service),\n+\t\t\t\"Invalid name\");\n+\tsnprintf(service.name, sizeof(service.name), DUMMY_SERVICE_NAME);\n+\tTEST_ASSERT_EQUAL(0, rte_service_register(&service),\n+\t\t\t\"Failed to register valid service\");\n+\n+\t/* ensure with dummy services registered returns same ptr as ID */\n+\tstruct rte_service_spec *s_by_id = rte_service_get_by_id(0);\n+\tTEST_ASSERT_EQUAL(s_by_id, rte_service_get_by_name(DUMMY_SERVICE_NAME),\n+\t\t\t\"Service get_by_name should equal get_by_id()\");\n+\n+\tunregister_all();\n+\n+\t/* ensure after unregister, get_by_name returns NULL */\n+\tTEST_ASSERT_EQUAL(0, rte_service_get_by_name(DUMMY_SERVICE_NAME),\n+\t\t\t\"get by name should return NULL after unregister\");\n+\n+\treturn TEST_SUCCESS;\n+}\n+\n+/* verify probe of capabilities */\n+static int\n+service_probe_capability(void)\n+{\n+\tunregister_all();\n+\n+\tstruct rte_service_spec service;\n+\tmemset(&service, 0, sizeof(struct rte_service_spec));\n+\tservice.callback = dummy_cb;\n+\tsnprintf(service.name, sizeof(service.name), DUMMY_SERVICE_NAME);\n+\tservice.capabilities |= RTE_SERVICE_CAP_MT_SAFE;\n+\tTEST_ASSERT_EQUAL(0, rte_service_register(&service),\n+\t\t\t\"Register of MT SAFE service failed\");\n+\n+\t/* verify flag is enabled */\n+\tstruct rte_service_spec *s = rte_service_get_by_id(0);\n+\tint32_t mt = rte_service_probe_capability(s, RTE_SERVICE_CAP_MT_SAFE);\n+\tTEST_ASSERT_EQUAL(1, mt, \"MT SAFE capability flag not set.\");\n+\n+\n+\tunregister_all();\n+\n+\tmemset(&service, 0, sizeof(struct rte_service_spec));\n+\tservice.callback = dummy_cb;\n+\tsnprintf(service.name, sizeof(service.name), DUMMY_SERVICE_NAME);\n+\tTEST_ASSERT_EQUAL(0, rte_service_register(&service),\n+\t\t\t\"Register of non-MT safe service failed\");\n+\n+\t/* verify flag is enabled */\n+\ts = rte_service_get_by_id(0);\n+\tmt = rte_service_probe_capability(s, RTE_SERVICE_CAP_MT_SAFE);\n+\tTEST_ASSERT_EQUAL(0, mt, \"MT SAFE cap flag set on non MT SAFE service\");\n+\n+\treturn unregister_all();\n+}\n+\n+/* verify the service name */\n+static int\n+service_name(void)\n+{\n+\tstruct rte_service_spec *service = rte_service_get_by_id(0);\n+\n+\tint equal = strcmp(service->name, DUMMY_SERVICE_NAME);\n+\tTEST_ASSERT_EQUAL(0, equal, \"Error: Service name not correct\");\n+\n+\treturn unregister_all();\n+}\n+\n+/* verify service dump */\n+static int\n+service_dump(void)\n+{\n+\tstruct rte_service_spec *service = rte_service_get_by_id(0);\n+\trte_service_set_stats_enable(service, 1);\n+\trte_service_dump(stdout, service);\n+\trte_service_set_stats_enable(service, 0);\n+\trte_service_dump(stdout, service);\n+\treturn unregister_all();\n+}\n+\n+/* start and stop a service */\n+static int\n+service_start_stop(void)\n+{\n+\tstruct rte_service_spec *service = rte_service_get_by_id(0);\n+\n+\t/* is_running() returns if service is running and slcore is mapped */\n+\tTEST_ASSERT_EQUAL(0, rte_service_lcore_add(slcore_id),\n+\t\t\t\"Service core add did not return zero\");\n+\tint ret = rte_service_enable_on_lcore(service, slcore_id);\n+\tTEST_ASSERT_EQUAL(0, ret,\n+\t\t\t\"Enabling service core, expected 0 got %d\", ret);\n+\n+\tTEST_ASSERT_EQUAL(0, rte_service_is_running(service),\n+\t\t\t\"Error: Service should be stopped\");\n+\n+\tTEST_ASSERT_EQUAL(0, rte_service_stop(service),\n+\t\t\t\"Error: Service stopped returned non-zero\");\n+\n+\tTEST_ASSERT_EQUAL(0, rte_service_is_running(service),\n+\t\t\t\"Error: Service is running - should be stopped\");\n+\n+\tTEST_ASSERT_EQUAL(0, rte_service_start(service),\n+\t\t\t\"Error: Service start returned non-zero\");\n+\n+\tTEST_ASSERT_EQUAL(1, rte_service_is_running(service),\n+\t\t\t\"Error: Service is not running\");\n+\n+\treturn unregister_all();\n+}\n+\n+\n+static int\n+service_remote_launch_func(void *arg)\n+{\n+\tRTE_SET_USED(arg);\n+\tservice_remote_launch_flag = 1;\n+\treturn 0;\n+}\n+\n+/* enable and disable a lcore for a service */\n+static int\n+service_lcore_en_dis_able(void)\n+{\n+\tstruct rte_service_spec *s = rte_service_get_by_id(0);\n+\n+\t/* expected failure cases */\n+\tTEST_ASSERT_EQUAL(-EINVAL, rte_service_enable_on_lcore(s, 100000),\n+\t\t\t\"Enable on invalid core did not fail\");\n+\tTEST_ASSERT_EQUAL(-EINVAL, rte_service_disable_on_lcore(s, 100000),\n+\t\t\t\"Disable on invalid core did not fail\");\n+\n+\t/* add service core to allow enabling */\n+\tTEST_ASSERT_EQUAL(0, rte_service_lcore_add(slcore_id),\n+\t\t\t\"Add service core failed when not in use before\");\n+\n+\t/* valid enable */\n+\tTEST_ASSERT_EQUAL(0, rte_service_enable_on_lcore(s, slcore_id),\n+\t\t\t\"Enabling valid service and core failed\");\n+\tTEST_ASSERT_EQUAL(1, rte_service_get_enabled_on_lcore(s, slcore_id),\n+\t\t\t\"Enabled core returned not-enabled\");\n+\n+\t/* valid disable */\n+\tTEST_ASSERT_EQUAL(0, rte_service_disable_on_lcore(s, slcore_id),\n+\t\t\t\"Disabling valid service and lcore failed\");\n+\tTEST_ASSERT_EQUAL(0, rte_service_get_enabled_on_lcore(s, slcore_id),\n+\t\t\t\"Disabled core returned enabled\");\n+\n+\t/* call remote_launch to verify that app can launch ex-service lcore */\n+\tservice_remote_launch_flag = 0;\n+\tint ret = rte_eal_remote_launch(service_remote_launch_func, NULL,\n+\t\t\t\t\tslcore_id);\n+\tTEST_ASSERT_EQUAL(0, ret, \"Ex-service core remote launch failed.\");\n+\trte_eal_mp_wait_lcore();\n+\tTEST_ASSERT_EQUAL(1, service_remote_launch_flag,\n+\t\t\t\"Ex-service core function call had no effect.\");\n+\n+\treturn unregister_all();\n+}\n+\n+static int\n+service_lcore_running_check(void)\n+{\n+\tuint64_t tick = service_tick;\n+\trte_delay_ms(SERVICE_DELAY * 10);\n+\t/* if (tick != service_tick) we know the lcore as polled the service */\n+\treturn tick != service_tick;\n+}\n+\n+static int\n+service_lcore_add_del(void)\n+{\n+\t/* check initial count */\n+\tTEST_ASSERT_EQUAL(0, rte_service_lcore_count(),\n+\t\t\t\"Service lcore count has value before adding a lcore\");\n+\n+\t/* check service lcore add */\n+\tTEST_ASSERT_EQUAL(0, rte_service_lcore_add(slcore_id),\n+\t\t\t\"Add service core failed when not in use before\");\n+\tTEST_ASSERT_EQUAL(-EALREADY, rte_service_lcore_add(slcore_id),\n+\t\t\t\"Add service core failed to refuse in-use lcore\");\n+\n+\t/* check count */\n+\tTEST_ASSERT_EQUAL(1, rte_service_lcore_count(),\n+\t\t\t\"Service core count not equal to one\");\n+\n+\t/* retrieve core list, checking lcore ids */\n+\tconst uint32_t size = 4;\n+\tuint32_t service_core_ids[size];\n+\tint32_t n = rte_service_lcore_list(service_core_ids, size);\n+\tTEST_ASSERT_EQUAL(1, n, \"Service core list return should equal 1\");\n+\tTEST_ASSERT_EQUAL(slcore_id, service_core_ids[0],\n+\t\t\t\t\"Service core list lcore must equal slcore_id\");\n+\n+\t/* recheck count, add more cores, and check count */\n+\tTEST_ASSERT_EQUAL(1, rte_service_lcore_count(),\n+\t\t\t\"Service core count not equal to one\");\n+\tuint32_t slcore_1 = rte_get_next_lcore(/* start core */ -1,\n+\t\t\t\t\t       /* skip master */ 1,\n+\t\t\t\t\t       /* wrap */ 0);\n+\tTEST_ASSERT_EQUAL(0, rte_service_lcore_add(slcore_1),\n+\t\t\t\"Service core add did not return zero\");\n+\tuint32_t slcore_2 = rte_get_next_lcore(/* start core */ slcore_1,\n+\t\t\t\t\t       /* skip master */ 1,\n+\t\t\t\t\t       /* wrap */ 0);\n+\tTEST_ASSERT_EQUAL(0, rte_service_lcore_add(slcore_2),\n+\t\t\t\"Service core add did not return zero\");\n+\n+\tuint32_t count = rte_service_lcore_count();\n+\tconst uint32_t cores_at_this_point = 3;\n+\tTEST_ASSERT_EQUAL(cores_at_this_point, count,\n+\t\t\t\"Service core count %d, expected %d\", count,\n+\t\t\tcores_at_this_point);\n+\n+\t/* check longer service core list */\n+\tn = rte_service_lcore_list(service_core_ids, size);\n+\tTEST_ASSERT_EQUAL(3, n, \"Service core list return should equal 3\");\n+\tTEST_ASSERT_EQUAL(slcore_id, service_core_ids[0],\n+\t\t\t\t\"Service core list[0] lcore must equal 1\");\n+\tTEST_ASSERT_EQUAL(slcore_1, service_core_ids[1],\n+\t\t\t\t\"Service core list[1] lcore must equal 2\");\n+\tTEST_ASSERT_EQUAL(slcore_2, service_core_ids[2],\n+\t\t\t\t\"Service core list[2] lcore must equal 3\");\n+\n+\t/* recheck count, remove lcores, check remaining lcore_id is correct */\n+\tTEST_ASSERT_EQUAL(3, rte_service_lcore_count(),\n+\t\t\t\"Service core count not equal to three\");\n+\tTEST_ASSERT_EQUAL(0, rte_service_lcore_del(slcore_1),\n+\t\t\t\"Service core add did not return zero\");\n+\tTEST_ASSERT_EQUAL(0, rte_service_lcore_del(slcore_2),\n+\t\t\t\"Service core add did not return zero\");\n+\tTEST_ASSERT_EQUAL(1, rte_service_lcore_count(),\n+\t\t\t\"Service core count not equal to one\");\n+\tn = rte_service_lcore_list(service_core_ids, size);\n+\tTEST_ASSERT_EQUAL(1, n, \"Service core list return should equal one\");\n+\tTEST_ASSERT_EQUAL(slcore_id, service_core_ids[0],\n+\t\t\t\t\"Service core list[0] lcore must equal %d\",\n+\t\t\t\tslcore_id);\n+\n+\treturn unregister_all();\n+}\n+\n+static int\n+service_threaded_test(int mt_safe)\n+{\n+\tunregister_all();\n+\n+\t/* add next 2 cores */\n+\tuint32_t slcore_1 = rte_get_next_lcore(/* start core */ -1,\n+\t\t\t\t\t       /* skip master */ 1,\n+\t\t\t\t\t       /* wrap */ 0);\n+\tTEST_ASSERT_EQUAL(0, rte_service_lcore_add(slcore_1),\n+\t\t\t\"mt safe lcore add fail\");\n+\tuint32_t slcore_2 = rte_get_next_lcore(/* start core */ slcore_1,\n+\t\t\t\t\t       /* skip master */ 1,\n+\t\t\t\t\t       /* wrap */ 0);\n+\tTEST_ASSERT_EQUAL(0, rte_service_lcore_add(slcore_2),\n+\t\t\t\"mt safe lcore add fail\");\n+\n+\t/* Use atomic locks to verify that two threads are in the same function\n+\t * at the same time. These are passed to the unit tests through the\n+\t * callback userdata parameter\n+\t */\n+\tuint32_t test_params[2];\n+\tmemset(test_params, 0, sizeof(uint32_t) * 2);\n+\n+\t/* register MT safe service. */\n+\tstruct rte_service_spec service;\n+\tmemset(&service, 0, sizeof(struct rte_service_spec));\n+\tservice.callback_userdata = test_params;\n+\tsnprintf(service.name, sizeof(service.name), MT_SAFE_SERVICE_NAME);\n+\n+\tif (mt_safe) {\n+\t\tservice.callback = dummy_mt_safe_cb;\n+\t\tservice.capabilities |= RTE_SERVICE_CAP_MT_SAFE;\n+\t} else {\n+\t\t/* initialize to pass, see callback comment for details */\n+\t\ttest_params[1] = 1;\n+\t\tservice.callback = dummy_mt_unsafe_cb;\n+\t}\n+\n+\tTEST_ASSERT_EQUAL(0, rte_service_register(&service),\n+\t\t\t\"Register of MT SAFE service failed\");\n+\n+\tstruct rte_service_spec *s = rte_service_get_by_id(0);\n+\tTEST_ASSERT_EQUAL(0, rte_service_start(s),\n+\t\t\t\"Starting valid service failed\");\n+\tTEST_ASSERT_EQUAL(0, rte_service_enable_on_lcore(s, slcore_1),\n+\t\t\t\"Failed to enable lcore 1 on mt safe service\");\n+\tTEST_ASSERT_EQUAL(0, rte_service_enable_on_lcore(s, slcore_2),\n+\t\t\t\"Failed to enable lcore 2 on mt safe service\");\n+\trte_service_lcore_start(slcore_1);\n+\trte_service_lcore_start(slcore_2);\n+\n+\t/* wait for the worker threads to run */\n+\trte_delay_ms(500);\n+\trte_service_lcore_stop(slcore_1);\n+\trte_service_lcore_stop(slcore_2);\n+\n+\tTEST_ASSERT_EQUAL(1, test_params[1],\n+\t\t\t\"MT Safe service not run by two cores concurrently\");\n+\n+\tTEST_ASSERT_EQUAL(0, rte_service_stop(s),\n+\t\t\t\"Failed to stop MT Safe service\");\n+\n+\tunregister_all();\n+\n+\t/* return the value of the callback pass_test variable to caller */\n+\treturn test_params[1];\n+}\n+\n+/* tests an MT SAFE service with two cores. The callback function ensures that\n+ * two threads access the callback concurrently.\n+ */\n+static int\n+service_mt_safe_poll(void)\n+{\n+\tint mt_safe = 1;\n+\tTEST_ASSERT_EQUAL(1, service_threaded_test(mt_safe),\n+\t\t\t\"Error: MT Safe service not run by two cores concurrently\");\n+\treturn TEST_SUCCESS;\n+}\n+\n+/* tests a NON mt safe service with two cores, the callback is serialized\n+ * using the atomic cmpset.\n+ */\n+static int\n+service_mt_unsafe_poll(void)\n+{\n+\tint mt_safe = 0;\n+\tTEST_ASSERT_EQUAL(1, service_threaded_test(mt_safe),\n+\t\t\t\"Error: NON MT Safe service run by two cores concurrently\");\n+\treturn TEST_SUCCESS;\n+}\n+\n+/* start and stop a service core - ensuring it goes back to sleep */\n+static int\n+service_lcore_start_stop(void)\n+{\n+\t/* start service core and service, create mapping so tick() runs */\n+\tstruct rte_service_spec *s = rte_service_get_by_id(0);\n+\tTEST_ASSERT_EQUAL(0, rte_service_start(s),\n+\t\t\t\"Starting valid service failed\");\n+\tTEST_ASSERT_EQUAL(-EINVAL, rte_service_enable_on_lcore(s, slcore_id),\n+\t\t\t\"Enabling valid service on non-service core must fail\");\n+\n+\t/* core start */\n+\tTEST_ASSERT_EQUAL(-EINVAL, rte_service_lcore_start(slcore_id),\n+\t\t\t\"Service core start without add should return EINVAL\");\n+\tTEST_ASSERT_EQUAL(0, rte_service_lcore_add(slcore_id),\n+\t\t\t\"Service core add did not return zero\");\n+\tTEST_ASSERT_EQUAL(0, rte_service_enable_on_lcore(s, slcore_id),\n+\t\t\t\"Enabling valid service on valid core failed\");\n+\tTEST_ASSERT_EQUAL(0, rte_service_lcore_start(slcore_id),\n+\t\t\t\"Service core start after add failed\");\n+\tTEST_ASSERT_EQUAL(-EALREADY, rte_service_lcore_start(slcore_id),\n+\t\t\t\"Service core expected as running but was stopped\");\n+\n+\t/* ensures core really is running the service function */\n+\tTEST_ASSERT_EQUAL(1, service_lcore_running_check(),\n+\t\t\t\"Service core expected to poll service but it didn't\");\n+\n+\t/* core stop */\n+\tTEST_ASSERT_EQUAL(-EINVAL, rte_service_lcore_stop(100000),\n+\t\t\t\"Invalid Service core stop should return -EINVAL\");\n+\tTEST_ASSERT_EQUAL(0, rte_service_lcore_stop(slcore_id),\n+\t\t\t\"Service core stop expected to return 0\");\n+\tTEST_ASSERT_EQUAL(-EALREADY, rte_service_lcore_stop(slcore_id),\n+\t\t\t\"Already stopped service core should return -EALREADY\");\n+\n+\t/* ensure service is not longer running */\n+\tTEST_ASSERT_EQUAL(0, service_lcore_running_check(),\n+\t\t\t\"Service core expected to poll service but it didn't\");\n+\n+\tTEST_ASSERT_EQUAL(0, rte_service_lcore_del(slcore_id),\n+\t\t\t\"Service core del did not return zero\");\n+\n+\treturn unregister_all();\n+}\n+\n+static struct unit_test_suite service_tests  = {\n+\t.suite_name = \"service core test suite\",\n+\t.setup = testsuite_setup,\n+\t.teardown = testsuite_teardown,\n+\t.unit_test_cases = {\n+\t\tTEST_CASE_ST(dummy_register, NULL, unregister_all),\n+\t\tTEST_CASE_ST(dummy_register, NULL, service_name),\n+\t\tTEST_CASE_ST(dummy_register, NULL, service_get_by_name),\n+\t\tTEST_CASE_ST(dummy_register, NULL, service_dump),\n+\t\tTEST_CASE_ST(dummy_register, NULL, service_probe_capability),\n+\t\tTEST_CASE_ST(dummy_register, NULL, service_start_stop),\n+\t\tTEST_CASE_ST(dummy_register, NULL, service_lcore_add_del),\n+\t\tTEST_CASE_ST(dummy_register, NULL, service_lcore_start_stop),\n+\t\tTEST_CASE_ST(dummy_register, NULL, service_lcore_en_dis_able),\n+\t\tTEST_CASE_ST(dummy_register, NULL, service_mt_unsafe_poll),\n+\t\tTEST_CASE_ST(dummy_register, NULL, service_mt_safe_poll),\n+\t\tTEST_CASES_END() /**< NULL terminate unit test array */\n+\t}\n+};\n+\n+static int\n+test_service_common(void)\n+{\n+\treturn unit_test_suite_runner(&service_tests);\n+}\n+\n+REGISTER_TEST_COMMAND(service_autotest, test_service_common);\n",
    "prefixes": [
        "dpdk-dev",
        "v5",
        "4/7"
    ]
}