get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 69260,
    "url": "https://patches.dpdk.org/api/patches/69260/?format=api",
    "web_url": "https://patches.dpdk.org/project/dpdk/patch/20200424124159.45989-6-ciara.power@intel.com/",
    "project": {
        "id": 1,
        "url": "https://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": "<20200424124159.45989-6-ciara.power@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20200424124159.45989-6-ciara.power@intel.com",
    "date": "2020-04-24T12:41:46",
    "name": "[v4,05/18] telemetry: add utility functions for creating json",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "d0be750cd9ce752f7d8d07072fe4a7c7eaeb95b4",
    "submitter": {
        "id": 978,
        "url": "https://patches.dpdk.org/api/people/978/?format=api",
        "name": "Power, Ciara",
        "email": "ciara.power@intel.com"
    },
    "delegate": {
        "id": 1,
        "url": "https://patches.dpdk.org/api/users/1/?format=api",
        "username": "tmonjalo",
        "first_name": "Thomas",
        "last_name": "Monjalon",
        "email": "thomas@monjalon.net"
    },
    "mbox": "https://patches.dpdk.org/project/dpdk/patch/20200424124159.45989-6-ciara.power@intel.com/mbox/",
    "series": [
        {
            "id": 9624,
            "url": "https://patches.dpdk.org/api/series/9624/?format=api",
            "web_url": "https://patches.dpdk.org/project/dpdk/list/?series=9624",
            "date": "2020-04-24T12:41:41",
            "name": "update and simplify telemetry library.",
            "version": 4,
            "mbox": "https://patches.dpdk.org/series/9624/mbox/"
        }
    ],
    "comments": "https://patches.dpdk.org/api/patches/69260/comments/",
    "check": "fail",
    "checks": "https://patches.dpdk.org/api/patches/69260/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@inbox.dpdk.org",
        "Delivered-To": "patchwork@inbox.dpdk.org",
        "Received": [
            "from dpdk.org (dpdk.org [92.243.14.124])\n\tby inbox.dpdk.org (Postfix) with ESMTP id A6108A00C2;\n\tFri, 24 Apr 2020 15:02:47 +0200 (CEST)",
            "from [92.243.14.124] (localhost [127.0.0.1])\n\tby dpdk.org (Postfix) with ESMTP id 59BA01C2BF;\n\tFri, 24 Apr 2020 15:02:14 +0200 (CEST)",
            "from mga02.intel.com (mga02.intel.com [134.134.136.20])\n by dpdk.org (Postfix) with ESMTP id 16ECF1C240\n for <dev@dpdk.org>; Fri, 24 Apr 2020 15:02:07 +0200 (CEST)",
            "from orsmga007.jf.intel.com ([10.7.209.58])\n by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;\n 24 Apr 2020 06:01:54 -0700",
            "from silpixa00399953.ir.intel.com (HELO\n silpixa00399953.ger.corp.intel.com) ([10.237.222.53])\n by orsmga007.jf.intel.com with ESMTP; 24 Apr 2020 06:01:51 -0700"
        ],
        "IronPort-SDR": [
            "\n gXJoBc0TS2Kw3+EJrddOHGAIYFIN25fcrknlsaVRZRLaINwZW8p9GCjDbBGoU/X5a6UgsfrB78\n Hxw+SKPfyB6g==",
            "\n j5dWz44mgyWfMv7jiqXrJsHbol/gVJTgGtTeA3zIv8rvxj7P/Ate3EqePFczd39NqtVbwmhwwx\n lZJ9HaVPar/Q=="
        ],
        "X-Amp-Result": "SKIPPED(no attachment in message)",
        "X-Amp-File-Uploaded": "False",
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos;i=\"5.73,311,1583222400\"; d=\"scan'208\";a=\"245228265\"",
        "From": "Ciara Power <ciara.power@intel.com>",
        "To": "dev@dpdk.org,\n\tkevin.laatz@intel.com",
        "Cc": "reshma.pattan@intel.com, jerinjacobk@gmail.com, david.marchand@redhat.com,\n keith.wiles@intel.com, mb@smartsharesystems.com, thomas@monjalon.net,\n Bruce Richardson <bruce.richardson@intel.com>",
        "Date": "Fri, 24 Apr 2020 13:41:46 +0100",
        "Message-Id": "<20200424124159.45989-6-ciara.power@intel.com>",
        "X-Mailer": "git-send-email 2.17.1",
        "In-Reply-To": "<20200424124159.45989-1-ciara.power@intel.com>",
        "References": "<20200319171907.60891-1-ciara.power@intel.com>\n <20200424124159.45989-1-ciara.power@intel.com>",
        "Subject": "[dpdk-dev] [PATCH v4 05/18] telemetry: add utility functions for\n\tcreating json",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.15",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n <mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://mails.dpdk.org/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n <mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>"
    },
    "content": "From: Bruce Richardson <bruce.richardson@intel.com>\n\nThe functions added in this patch will make it easier for telemetry\nto convert data to correct JSON responses to telemetry requests.\nTests are also  added for these json utility functions.\n\nSigned-off-by: Bruce Richardson <bruce.richardson@intel.com>\n\n---\nv4: Tests included in patch with utility functions\n---\n app/test/Makefile                     |   2 +\n app/test/meson.build                  |   4 +\n app/test/test_telemetry_json.c        | 136 ++++++++++++++++++++++\n lib/librte_telemetry/telemetry_json.h | 158 ++++++++++++++++++++++++++\n 4 files changed, 300 insertions(+)\n create mode 100644 app/test/test_telemetry_json.c\n create mode 100644 lib/librte_telemetry/telemetry_json.h",
    "diff": "diff --git a/app/test/Makefile b/app/test/Makefile\nindex 4582eca6cf..e5c07ddf18 100644\n--- a/app/test/Makefile\n+++ b/app/test/Makefile\n@@ -141,6 +141,8 @@ SRCS-$(CONFIG_RTE_LIBRTE_LPM) += test_lpm_perf.c\n SRCS-$(CONFIG_RTE_LIBRTE_LPM) += test_lpm6.c\n SRCS-$(CONFIG_RTE_LIBRTE_LPM) += test_lpm6_perf.c\n \n+SRCS-$(CONFIG_RTE_LIBRTE_TELEMETRY) += test_telemetry_json.c\n+\n SRCS-y += test_debug.c\n SRCS-y += test_errno.c\n SRCS-y += test_tailq.c\ndiff --git a/app/test/meson.build b/app/test/meson.build\nindex a9a8eabcd9..d98daf5ff3 100644\n--- a/app/test/meson.build\n+++ b/app/test/meson.build\n@@ -333,6 +333,10 @@ endif\n if dpdk_conf.has('RTE_LIBRTE_SKELETON_EVENTDEV_PMD')\n \ttest_deps += 'pmd_skeleton_event'\n endif\n+if dpdk_conf.has('RTE_LIBRTE_TELEMETRY')\n+\ttest_sources += 'test_telemetry_json.c'\n+\tfast_tests += [['telemetry_json_autotest', true]]\n+endif\n \n # The following linkages of drivers are required because\n # they are used via a driver-specific API.\ndiff --git a/app/test/test_telemetry_json.c b/app/test/test_telemetry_json.c\nnew file mode 100644\nindex 0000000000..90bbb3e8d9\n--- /dev/null\n+++ b/app/test/test_telemetry_json.c\n@@ -0,0 +1,136 @@\n+/* SPDX-License-Identifier: BSD-3-Clause\n+ * Copyright 2020 Intel Corporation\n+ */\n+\n+#include <string.h>\n+\n+#include \"../../lib/librte_telemetry/telemetry_json.h\"\n+#include \"test.h\"\n+\n+static int\n+test_basic_array(void)\n+{\n+\tconst char *expected = \"[\\\"meaning of life\\\",42]\";\n+\tchar buf[1024];\n+\tint used = 0;\n+\n+\tprintf(\"%s: \", __func__);\n+\tused = rte_tel_json_empty_array(buf, sizeof(buf), used);\n+\tif (used != 2 || strcmp(buf, \"[]\"))\n+\t\treturn -1;\n+\n+\tused = rte_tel_json_add_array_string(buf, sizeof(buf), used,\n+\t\t\"meaning of life\");\n+\tused = rte_tel_json_add_array_int(buf, sizeof(buf), used, 42);\n+\n+\tprintf(\"buf = '%s', expected = '%s'\\n\", buf, expected);\n+\tif (used != (int)strlen(expected))\n+\t\treturn -1;\n+\treturn strncmp(expected, buf, sizeof(buf));\n+}\n+\n+static int\n+test_basic_obj(void)\n+{\n+\tconst char *expected = \"{\\\"weddings\\\":4,\\\"funerals\\\":1}\";\n+\tchar buf[1024];\n+\tint used = 0;\n+\n+\tused = rte_tel_json_add_obj_u64(buf, sizeof(buf), used,\n+\t\t\"weddings\", 4);\n+\tused = rte_tel_json_add_obj_u64(buf, sizeof(buf), used,\n+\t\t\"funerals\", 1);\n+\n+\tprintf(\"%s: buf = '%s', expected = '%s'\\n\", __func__, buf, expected);\n+\tif (used != (int)strlen(expected))\n+\t\treturn -1;\n+\treturn strncmp(expected, buf, sizeof(buf));\n+}\n+\n+static int\n+test_overflow_array(void)\n+{\n+\tstatic const char * const strs[] = {\"Arsenal\", \"Chelsea\", \"Liverpool\",\n+\t\t\t\"Spurs\"};\n+\tconst char *expected = \"[\\\"Arsenal\\\",\\\"Chelsea\\\"]\";\n+\tchar buf[25];\n+\tint i, used = 0;\n+\n+\tfor (i = 0; i < (int)RTE_DIM(strs); i++)\n+\t\tused = rte_tel_json_add_array_string(buf, sizeof(buf), used,\n+\t\t\t\tstrs[i]);\n+\n+\tprintf(\"%s: buf = '%s', expected = '%s'\\n\", __func__, buf, expected);\n+\tif (buf[used - 1] != ']')\n+\t\treturn -1;\n+\tif (used != (int)strlen(expected))\n+\t\treturn -1;\n+\treturn strncmp(expected, buf, sizeof(buf));\n+}\n+\n+static int\n+test_overflow_obj(void)\n+{\n+\tstatic const char * const names[] = {\"Italy\", \"Wales\", \"Scotland\",\n+\t\t\t\"Ireland\", \"England\", \"France\"};\n+\tconst int vals[RTE_DIM(names)] = {20, 61, 10, 40, 55, 35};\n+\tconst char *expected = \"{\\\"Italy\\\":20,\\\"Wales\\\":61}\";\n+\tchar buf[25];\n+\tint i, used = 0;\n+\n+\tfor (i = 0; i < (int)RTE_DIM(names); i++)\n+\t\tused = rte_tel_json_add_obj_u64(buf, sizeof(buf), used,\n+\t\t\t\tnames[i], vals[i]);\n+\n+\tprintf(\"%s: buf = '%s', expected = '%s'\\n\", __func__, buf, expected);\n+\tif (buf[used - 1] != '}')\n+\t\treturn -1;\n+\tif (used != (int)strlen(expected))\n+\t\treturn -1;\n+\treturn strncmp(expected, buf, sizeof(buf));\n+}\n+\n+static int\n+test_large_array_element(void)\n+{\n+\tstatic const char str[] = \"A really long string to overflow buffer\";\n+\t/* buffer should be unmodified so initial value and expected are same */\n+\tconst char *expected = \"ABC\";\n+\tchar buf[sizeof(str) - 5] = \"ABC\";\n+\tint used = 0;\n+\n+\tused = rte_tel_json_add_array_string(buf, sizeof(buf), used, str);\n+\tprintf(\"%s: buf = '%s', expected = '%s'\\n\", __func__, buf, expected);\n+\n+\treturn strlen(buf) != 0;\n+}\n+\n+static int\n+test_large_obj_element(void)\n+{\n+\tstatic const char str[] = \"A really long string to overflow buffer\";\n+\t/* buffer should be unmodified so initial value and expected are same */\n+\tconst char *expected = \"XYZ\";\n+\tchar buf[sizeof(str) - 5] = \"XYZ\";\n+\tint used = 0;\n+\n+\tused = rte_tel_json_add_obj_u64(buf, sizeof(buf), used, str, 0);\n+\tprintf(\"%s: buf = '%s', expected = '%s'\\n\", __func__, buf, expected);\n+\n+\treturn strlen(buf) != 0;\n+}\n+\n+static int\n+test_telemetry_json(void)\n+{\n+\tif (test_basic_array() < 0 ||\n+\t\t\ttest_basic_obj() < 0 ||\n+\t\t\ttest_overflow_array() < 0 ||\n+\t\t\ttest_overflow_obj() < 0 ||\n+\t\t\ttest_large_array_element() < 0 ||\n++\t\t\ttest_large_obj_element() < 0)\n+\t\treturn -1;\n+\treturn 0;\n+}\n+\n+REGISTER_TEST_COMMAND(telemetry_json_autotest, test_telemetry_json);\ndiff --git a/lib/librte_telemetry/telemetry_json.h b/lib/librte_telemetry/telemetry_json.h\nnew file mode 100644\nindex 0000000000..a2ce4899e0\n--- /dev/null\n+++ b/lib/librte_telemetry/telemetry_json.h\n@@ -0,0 +1,158 @@\n+/* SPDX-License-Identifier: BSD-3-Clause\n+ * Copyright(c) 2020 Intel Corporation\n+ */\n+\n+#ifndef _RTE_TELEMETRY_JSON_H_\n+#define _RTE_TELEMETRY_JSON_H_\n+\n+#include <inttypes.h>\n+#include <stdarg.h>\n+#include <stdio.h>\n+#include <rte_common.h>\n+\n+/**\n+ * @file\n+ * Internal Telemetry Utility functions\n+ *\n+ * This file contains small inline functions to make it easier for applications\n+ * to build up valid JSON responses to telemetry requests.\n+ *\n+ ***/\n+\n+/**\n+ * @internal\n+ * Copies a value into a buffer if the buffer has enough available space.\n+ * Nothing written to buffer if an overflow ocurs.\n+ * This function is not for use for values larger than 1k.\n+ */\n+__rte_format_printf(3, 4)\n+static inline int\n+__json_snprintf(char *buf, const int len, const char *format, ...)\n+{\n+\tchar tmp[1024];\n+\tva_list ap;\n+\tint ret;\n+\n+\tva_start(ap, format);\n+\tret = vsnprintf(tmp, sizeof(tmp), format, ap);\n+\tva_end(ap);\n+\tif (ret > 0 && ret < (int)sizeof(tmp) && ret < len) {\n+\t\tstrcpy(buf, tmp);\n+\t\treturn ret;\n+\t}\n+\treturn 0; /* nothing written or modified */\n+}\n+\n+/* Copies an empty array into the provided buffer. */\n+static inline int\n+rte_tel_json_empty_array(char *buf, const int len, const int used)\n+{\n+\treturn used + __json_snprintf(buf + used, len - used, \"[]\");\n+}\n+\n+/* Copies an empty object into the provided buffer. */\n+static inline int\n+rte_tel_json_empty_obj(char *buf, const int len, const int used)\n+{\n+\treturn used + __json_snprintf(buf + used, len - used, \"{}\");\n+}\n+\n+/* Copies a string into the provided buffer, in JSON format. */\n+static inline int\n+rte_tel_json_str(char *buf, const int len, const int used, const char *str)\n+{\n+\treturn used + __json_snprintf(buf + used, len - used, \"\\\"%s\\\"\", str);\n+}\n+\n+/* Appends a string into the JSON array in the provided buffer. */\n+static inline int\n+rte_tel_json_add_array_string(char *buf, const int len, const int used,\n+\t\tconst char *str)\n+{\n+\tint ret, end = used - 1; /* strip off final delimiter */\n+\tif (used <= 2) /* assume empty, since minimum is '[]' */\n+\t\treturn __json_snprintf(buf, len, \"[\\\"%s\\\"]\", str);\n+\n+\tret = __json_snprintf(buf + end, len - end, \",\\\"%s\\\"]\", str);\n+\treturn ret == 0 ? used : end + ret;\n+}\n+\n+/* Appends an integer into the JSON array in the provided buffer. */\n+static inline int\n+rte_tel_json_add_array_int(char *buf, const int len, const int used, int val)\n+{\n+\tint ret, end = used - 1; /* strip off final delimiter */\n+\tif (used <= 2) /* assume empty, since minimum is '[]' */\n+\t\treturn __json_snprintf(buf, len, \"[%d]\", val);\n+\n+\tret = __json_snprintf(buf + end, len - end, \",%d]\", val);\n+\treturn ret == 0 ? used : end + ret;\n+}\n+\n+/* Appends a uint64_t into the JSON array in the provided buffer. */\n+static inline int\n+rte_tel_json_add_array_u64(char *buf, const int len, const int used,\n+\t\tuint64_t val)\n+{\n+\tint ret, end = used - 1; /* strip off final delimiter */\n+\tif (used <= 2) /* assume empty, since minimum is '[]' */\n+\t\treturn __json_snprintf(buf, len, \"[%\"PRIu64\"]\", val);\n+\n+\tret = __json_snprintf(buf + end, len - end, \",%\"PRIu64\"]\", val);\n+\treturn ret == 0 ? used : end + ret;\n+}\n+\n+/**\n+ * Add a new element with uint64_t value to the JSON object stored in the\n+ * provided buffer.\n+ */\n+static inline int\n+rte_tel_json_add_obj_u64(char *buf, const int len, const int used,\n+\t\tconst char *name, uint64_t val)\n+{\n+\tint ret, end = used - 1;\n+\tif (used <= 2) /* assume empty, since minimum is '{}' */\n+\t\treturn __json_snprintf(buf, len, \"{\\\"%s\\\":%\"PRIu64\"}\", name,\n+\t\t\t\tval);\n+\n+\tret = __json_snprintf(buf + end, len - end, \",\\\"%s\\\":%\"PRIu64\"}\",\n+\t\t\tname, val);\n+\treturn ret == 0 ? used : end + ret;\n+}\n+\n+/**\n+ * Add a new element with int value to the JSON object stored in the\n+ * provided buffer.\n+ */\n+static inline int\n+rte_tel_json_add_obj_int(char *buf, const int len, const int used,\n+\t\tconst char *name, int val)\n+{\n+\tint ret, end = used - 1;\n+\tif (used <= 2) /* assume empty, since minimum is '{}' */\n+\t\treturn __json_snprintf(buf, len, \"{\\\"%s\\\":%d}\", name,\n+\t\t\t\tval);\n+\n+\tret = __json_snprintf(buf + end, len - end, \",\\\"%s\\\":%d}\",\n+\t\t\tname, val);\n+\treturn ret == 0 ? used : end + ret;\n+}\n+\n+/**\n+ * Add a new element with string value to the JSON object stored in the\n+ * provided buffer.\n+ */\n+static inline int\n+rte_tel_json_add_obj_str(char *buf, const int len, const int used,\n+\t\tconst char *name, const char *val)\n+{\n+\tint ret, end = used - 1;\n+\tif (used <= 2) /* assume empty, since minimum is '{}' */\n+\t\treturn __json_snprintf(buf, len, \"{\\\"%s\\\":\\\"%s\\\"}\", name, val);\n+\n+\tret = __json_snprintf(buf + end, len - end, \",\\\"%s\\\":\\\"%s\\\"}\",\n+\t\t\tname, val);\n+\treturn ret == 0 ? used : end + ret;\n+}\n+\n+#endif /*_RTE_TELEMETRY_JSON_H_*/\n",
    "prefixes": [
        "v4",
        "05/18"
    ]
}