From patchwork Wed Jul 24 23:06:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Steadmon X-Patchwork-Id: 11057695 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E066D1399 for ; Wed, 24 Jul 2019 23:07:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CAECE2892A for ; Wed, 24 Jul 2019 23:07:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BEE1428932; Wed, 24 Jul 2019 23:07:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 271FD2892A for ; Wed, 24 Jul 2019 23:07:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729673AbfGXXHC (ORCPT ); Wed, 24 Jul 2019 19:07:02 -0400 Received: from mail-pg1-f202.google.com ([209.85.215.202]:40866 "EHLO mail-pg1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726388AbfGXXHC (ORCPT ); Wed, 24 Jul 2019 19:07:02 -0400 Received: by mail-pg1-f202.google.com with SMTP id m19so14859983pgv.7 for ; Wed, 24 Jul 2019 16:07:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to; bh=9HKbsgtFxro3KxqsWN+DjOZubk+eyfGb0C8bVOsFJyk=; b=K0S07VT4+4xYD37k1C9hAGj4kxhJjvcIYMxIXo4C9Vkacyc0UcnqYILAuG48lSlOyd jmetwEuJownRJ9JG7PF2MvuRTwU8D553jXjU30K8Bl0Cw6RUAqmYKh4eYNqG0GNZ/Gfh eW/AcUY6vawUzFJhVOO5VDoLKcVRjfu/QZWU2OTqvkw1ln49T8HUlm8f+j7RNZQc5OBU Ulbq/pqBmbrc2Qr2uLRLEtXJrOGW4nl5NlZ/3rlznotcsdFxIFCinJlo/a0zwAY5y0x7 2Ry7jYNJi6ISTI7WC0P9aC1Q2Q3Km2IRInbEH+wb3JboUYPQFVmnCWREiW739iVhbRJt etvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to; bh=9HKbsgtFxro3KxqsWN+DjOZubk+eyfGb0C8bVOsFJyk=; b=d1EyDyFVmtxQR+SJ0cOtEz6CjSWSw37gcUUsuqFQB3zaCzxcM0B4AwMk9LdIBpSIvT UsUanJva6mEmg+X2iebLF5nfGku3HnmNNER1l7xE6kivVyiuuEQYEE7K0kle8LsfnN3p s+nDIsV1gNvKqaTDWKiAusGFkLs5zkSWV/mdULU6X3sbrghKLUnFDtE7eIyStvWC35rD NUU8Dvr7RSZTww5+7onfJF1ydf5He1qBz0hrdEMkL7pK/0p8WEw2tE+oUbpou595ZRDb x1skclurAZaFRtZo6ky+5J7jWojkNgM3h1l1eRSaBN57RgUocLEA1z6Tf4gDtvI9/Cjd nvGQ== X-Gm-Message-State: APjAAAVgPe6+bgVm3lGo+BmbuLM4NXVo+mO3dXILJjlruf0ARQJPkui5 4E1rO+chbGaHVy1lJStb4s/+gNV92iUVX+n1yGTgiZTPU7LDAw+OHk1uldquv4F5jYIjV4jmrif vSmXV4LxdZVVXZ2pj6WuuadIGmc+gFDKd65qksEdXLnxMxk0Y7oJss4hA05De2uk= X-Google-Smtp-Source: APXvYqwuahq7xayqMs1Ij9yS2N8q6Is5gscocok8v42L6FxvR1t9e+UMDvQyXzamtt/hSXdu8DjztWo+2pUJ1g== X-Received: by 2002:a63:9249:: with SMTP id s9mr80831554pgn.356.1564009620063; Wed, 24 Jul 2019 16:07:00 -0700 (PDT) Date: Wed, 24 Jul 2019 16:06:51 -0700 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.22.0.709.g102302147b-goog Subject: [PATCH v3 1/3] trace2: Add a JSON schema for trace2 events From: Josh Steadmon To: git@vger.kernel.org, gitster@pobox.com, git@jeffhostetler.com, avarab@gmail.com, peff@peff.net, jnareb@gmail.com Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Define a JSON schema[1] that can be used to validate trace2 event objects. This can be used to add regression tests to verify that the event output format does not change unexpectedly. Four versions of the schema are provided: * event_schema.json is more permissive. It verifies that all expected fields are present in a trace event, but it allows traces to have unexpected additional fields. This allows the schema to be specified more concisely by factoring out the common fields into a reusable sub-schema. * strict_schema.json is more restrictive. It verifies that all expected fields are present and no unexpected fields are present in the trace event. Due to this additional restriction, the common fields cannot be factored out into a re-usable subschema (at least as-of draft-07) [2], and must be repeated for each event definition. * list_schema.json is like event_schema.json above, but validates a JSON array of trace events, rather than a single event. * strict_list_schema.json is like strict_schema.json above, but validates a JSON array of trace events, rather than a single event. [1]: https://json-schema.org/ [2]: https://json-schema.org/understanding-json-schema/reference/combining.html#allof Signed-off-by: Josh Steadmon --- t/trace_schema_validator/README | 23 + t/trace_schema_validator/event_schema.json | 398 ++++++++++++++ t/trace_schema_validator/list_schema.json | 401 ++++++++++++++ .../strict_list_schema.json | 514 ++++++++++++++++++ t/trace_schema_validator/strict_schema.json | 511 +++++++++++++++++ 5 files changed, 1847 insertions(+) create mode 100644 t/trace_schema_validator/README create mode 100644 t/trace_schema_validator/event_schema.json create mode 100644 t/trace_schema_validator/list_schema.json create mode 100644 t/trace_schema_validator/strict_list_schema.json create mode 100644 t/trace_schema_validator/strict_schema.json diff --git a/t/trace_schema_validator/README b/t/trace_schema_validator/README new file mode 100644 index 0000000000..45f0e6f0c4 --- /dev/null +++ b/t/trace_schema_validator/README @@ -0,0 +1,23 @@ +These JSON schemas[1] can be used to validate trace2 event objects. They +can be used to add regression tests to verify that the event output +format does not change unexpectedly. + +Four versions of the schema are provided: +* event_schema.json is more permissive. It verifies that all expected + fields are present in a trace event, but it allows traces to have + unexpected additional fields. This allows the schema to be specified + more concisely by factoring out the common fields into a reusable + sub-schema. +* strict_schema.json is more restrictive. It verifies that all expected + fields are present and no unexpected fields are present in the trace + event. Due to this additional restriction, the common fields cannot be + factored out into a re-usable subschema (at least as-of draft-07) [2], + and must be repeated for each event definition. +* list_schema.json is like event_schema.json above, but validates a JSON + array of trace events, rather than a single event. +* strict_list_schema.json is like strict_schema.json above, but + validates a JSON array of trace events, rather than a single event. + +[1]: https://json-schema.org/ +[2]: https://json-schema.org/understanding-json-schema/reference/combining.html#allof + diff --git a/t/trace_schema_validator/event_schema.json b/t/trace_schema_validator/event_schema.json new file mode 100644 index 0000000000..fb3fb7e488 --- /dev/null +++ b/t/trace_schema_validator/event_schema.json @@ -0,0 +1,398 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$id": "http://git-scm.com/schemas/event_schema.json", + "title": "trace2 permissive schema", + "description": "Permissive schema for trace2 event output that does not fail in the presence of unexpected fields.", + + "definitions": { + "event_common_fields": { + "type": "object", + "properties": { + "sid": { "type": "string" }, + "thread": { "type": "string" }, + "time": { + "type": "string", + "format": "date-time" + }, + "file": { "type": "string" }, + "line": { "type": "integer" }, + "repo": { "type": "integer" } + }, + "required": [ "sid", "thread" ] + }, + + "version_event": { + "allOf": [ + { "$ref": "#/definitions/event_common_fields" }, + { + "properties": { + "event": { "const": "version" }, + "evt": { "const": "1" }, + "exe": { "type": "string" } + }, + "required": [ "event", "evt", "exe" ] + } + ] + }, + + "start_event": { + "allOf": [ + { "$ref": "#/definitions/event_common_fields" }, + { + "properties": { + "event": { "const": "start" }, + "t_abs": { "type": "number" }, + "argv": { + "type": "array", + "items": { "type": "string" } + } + }, + "required": [ "event", "t_abs", "argv" ] + } + ] + }, + + "exit_event": { + "allOf": [ + { "$ref": "#/definitions/event_common_fields" }, + { + "properties": { + "event": { "const": "exit" }, + "t_abs": { "type": "number" }, + "code": { "type": "integer" } + }, + "required": [ "event", "t_abs", "code" ] + } + ] + }, + + "atexit_event": { + "allOf": [ + { "$ref": "#/definitions/event_common_fields" }, + { + "properties": { + "event": { "const": "atexit" }, + "t_abs": { "type": "number" }, + "code": { "type": "integer" } + }, + "required": [ "event", "t_abs", "code" ] + } + ] + }, + + "signal_event": { + "allOf": [ + { "$ref": "#/definitions/event_common_fields" }, + { + "properties": { + "event": { "const": "signal" }, + "t_abs": { "type": "number" }, + "signo": { "type": "integer" } + }, + "required": [ "event", "t_abs", "signo" ] + } + ] + }, + + "error_event": { + "allOf": [ + { "$ref": "#/definitions/event_common_fields" }, + { + "properties": { + "event": { "const": "error" }, + "msg": { "type": "string" }, + "fmt": { "type": "string" } + }, + "required": [ "event", "msg", "fmt" ] + } + ] + }, + + "cmd_path_event": { + "allOf": [ + { "$ref": "#/definitions/event_common_fields" }, + { + "properties": { + "event": { "const": "cmd_path" }, + "path": { "type": "string" } + }, + "required": [ "event", "path" ] + } + ] + }, + + "cmd_name_event": { + "allOf": [ + { "$ref": "#/definitions/event_common_fields" }, + { + "properties": { + "event": { "const": "cmd_name" }, + "name": { "type": "string" }, + "hierarchy": { "type": "string" } + }, + "required": [ "event", "name", "hierarchy" ] + } + ] + }, + + "cmd_mode_event": { + "allOf": [ + { "$ref": "#/definitions/event_common_fields" }, + { + "properties": { + "event": { "const": "cmd_mode" }, + "name": { "type": "string" } + }, + "required": [ "event", "name" ] + } + ] + }, + + "alias_event": { + "allOf": [ + { "$ref": "#/definitions/event_common_fields" }, + { + "properties": { + "event": { "const": "alias" }, + "alias": { "type": "string" }, + "argv": { + "type": "array", + "items": { "type": "string" } + } + }, + "required": [ "event", "alias", "argv" ] + } + ] + }, + + "child_start_event": { + "allOf": [ + { "$ref": "#/definitions/event_common_fields" }, + { + "properties": { + "event": { "const": "child_start" }, + "child_id": { "type": "integer" }, + "child_class": { "type": "string" }, + "use_shell": { "type": "boolean" }, + "argv": { + "type": "array", + "items": { "type": "string" } + }, + "hook_name": { "type": "string" }, + "cd": { "type": "string" } + }, + "required": [ + "event", "child_id", "child_class", "use_shell", "argv" + ] + } + ] + }, + + "child_exit_event": { + "allOf": [ + { "$ref": "#/definitions/event_common_fields" }, + { + "properties": { + "event": { "const": "child_exit" }, + "child_id": { "type": "integer" }, + "pid": { "type": "integer" }, + "code": { "type": "integer" }, + "t_rel": { "type": "number" } + }, + "required": [ "event", "child_id", "pid", "code", "t_rel" ] + } + ] + }, + + "exec_event": { + "allOf": [ + { "$ref": "#/definitions/event_common_fields" }, + { + "properties": { + "event": { "const": "exec" }, + "exec_id": { "type": "integer" }, + "exe": { "type": "string" }, + "argv": { + "type": "array", + "items": { "type": "string" } + } + }, + "required": [ "event", "exec_id", "exe", "argv" ] + } + ] + }, + + "exec_result_event": { + "allOf": [ + { "$ref": "#/definitions/event_common_fields" }, + { + "properties": { + "event": { "const": "exec_result" }, + "exec_id": { "type": "integer" }, + "code": { "type": "integer" } + }, + "required": [ "event", "exec_id", "code" ] + } + ] + }, + + "thread_start_event": { + "allOf": [ + { "$ref": "#/definitions/event_common_fields" }, + { + "properties": { + "event": { "const": "thread_start" }, + "thread": { "type": "string" } + }, + "required": [ "event", "thread" ] + } + ] + }, + + "thread_exit_event": { + "allOf": [ + { "$ref": "#/definitions/event_common_fields" }, + { + "properties": { + "event": { "const": "thread_exit" }, + "thread": { "type": "string" }, + "t_rel": { "type": "number" } + }, + "required": [ "event", "thread", "t_rel" ] + } + ] + }, + + "def_param_event": { + "allOf": [ + { "$ref": "#/definitions/event_common_fields" }, + { + "properties": { + "event": { "const": "def_param" }, + "param": { "type": "string" }, + "value": { "type": "string" } + }, + "required": [ "event", "param", "value" ] + } + ] + }, + + "def_repo_event": { + "allOf": [ + { "$ref": "#/definitions/event_common_fields" }, + { + "properties": { + "event": { "const": "def_repo" }, + "repo": { "type": "integer" }, + "worktree": { "type": "string" } + }, + "required": [ "event", "repo", "worktree" ] + } + ] + }, + + "region_enter_event": { + "allOf": [ + { "$ref": "#/definitions/event_common_fields" }, + { + "properties": { + "event": { "const": "region_enter" }, + "repo": { "type": "integer" }, + "nesting": { "type": "integer" }, + "category": { "type": "string" }, + "label": { "type": "string" }, + "msg": { "type": "string" } + }, + "required": [ "event", "nesting" ] + } + ] + }, + + "region_leave_event": { + "allOf": [ + { "$ref": "#/definitions/event_common_fields" }, + { + "properties": { + "event": { "const": "region_leave" }, + "repo": { "type": "integer" }, + "t_rel": { "type": "number" }, + "nesting": { "type": "integer" }, + "category": { "type": "string" }, + "label": { "type": "string" }, + "msg": { "type": "string" } + }, + "required": [ "event", "t_rel", "nesting" ] + } + ] + }, + + "data_event": { + "allOf": [ + { "$ref": "#/definitions/event_common_fields" }, + { + "properties": { + "event": { "const": "data" }, + "repo": { "type": "integer" }, + "t_abs": { "type": "number" }, + "t_rel": { "type": "number" }, + "nesting": { "type": "integer" }, + "category": { "type": "string" }, + "key": { "type": "string" }, + "value": { "type": "string" } + }, + "required": [ + "event", "t_abs", "t_rel", "nesting", "category", "key", + "value" + ] + } + ] + }, + + "data-json_event": { + "allOf": [ + { "$ref": "#/definitions/event_common_fields" }, + { + "properties": { + "event": { "const": "data-json" }, + "repo": { "type": "integer" }, + "t_abs": { "type": "number" }, + "t_rel": { "type": "number" }, + "nesting": { "type": "integer" }, + "category": { "type": "string" }, + "key": { "type": "string" }, + "value": { "type": "object" } + }, + "required": [ + "event", "t_abs", "t_rel", "nesting", "category", "key", + "value" + ] + } + ] + } + }, + + "oneOf": [ + { "$ref": "#/definitions/version_event" }, + { "$ref": "#/definitions/start_event" }, + { "$ref": "#/definitions/exit_event" }, + { "$ref": "#/definitions/atexit_event" }, + { "$ref": "#/definitions/signal_event" }, + { "$ref": "#/definitions/error_event" }, + { "$ref": "#/definitions/cmd_path_event" }, + { "$ref": "#/definitions/cmd_name_event" }, + { "$ref": "#/definitions/cmd_mode_event" }, + { "$ref": "#/definitions/alias_event" }, + { "$ref": "#/definitions/child_start_event" }, + { "$ref": "#/definitions/child_exit_event" }, + { "$ref": "#/definitions/exec_event" }, + { "$ref": "#/definitions/exec_result_event" }, + { "$ref": "#/definitions/thread_start_event" }, + { "$ref": "#/definitions/thread_exit_event" }, + { "$ref": "#/definitions/def_param_event" }, + { "$ref": "#/definitions/def_repo_event" }, + { "$ref": "#/definitions/region_enter_event" }, + { "$ref": "#/definitions/region_leave_event" }, + { "$ref": "#/definitions/data_event" }, + { "$ref": "#/definitions/data-json_event" } + ] +} diff --git a/t/trace_schema_validator/list_schema.json b/t/trace_schema_validator/list_schema.json new file mode 100644 index 0000000000..db33db9d49 --- /dev/null +++ b/t/trace_schema_validator/list_schema.json @@ -0,0 +1,401 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$id": "http://git-scm.com/schemas/event_schema.json", + "title": "trace2 permissive schema", + "description": "Permissive schema for trace2 event output that does not fail in the presence of unexpected fields.", + + "definitions": { + "event_common_fields": { + "type": "object", + "properties": { + "sid": { "type": "string" }, + "thread": { "type": "string" }, + "time": { + "type": "string", + "format": "date-time" + }, + "file": { "type": "string" }, + "line": { "type": "integer" }, + "repo": { "type": "integer" } + }, + "required": [ "sid", "thread" ] + }, + + "version_event": { + "allOf": [ + { "$ref": "#/definitions/event_common_fields" }, + { + "properties": { + "event": { "const": "version" }, + "evt": { "const": "1" }, + "exe": { "type": "string" } + }, + "required": [ "event", "evt", "exe" ] + } + ] + }, + + "start_event": { + "allOf": [ + { "$ref": "#/definitions/event_common_fields" }, + { + "properties": { + "event": { "const": "start" }, + "t_abs": { "type": "number" }, + "argv": { + "type": "array", + "items": { "type": "string" } + } + }, + "required": [ "event", "t_abs", "argv" ] + } + ] + }, + + "exit_event": { + "allOf": [ + { "$ref": "#/definitions/event_common_fields" }, + { + "properties": { + "event": { "const": "exit" }, + "t_abs": { "type": "number" }, + "code": { "type": "integer" } + }, + "required": [ "event", "t_abs", "code" ] + } + ] + }, + + "atexit_event": { + "allOf": [ + { "$ref": "#/definitions/event_common_fields" }, + { + "properties": { + "event": { "const": "atexit" }, + "t_abs": { "type": "number" }, + "code": { "type": "integer" } + }, + "required": [ "event", "t_abs", "code" ] + } + ] + }, + + "signal_event": { + "allOf": [ + { "$ref": "#/definitions/event_common_fields" }, + { + "properties": { + "event": { "const": "signal" }, + "t_abs": { "type": "number" }, + "signo": { "type": "integer" } + }, + "required": [ "event", "t_abs", "signo" ] + } + ] + }, + + "error_event": { + "allOf": [ + { "$ref": "#/definitions/event_common_fields" }, + { + "properties": { + "event": { "const": "error" }, + "msg": { "type": "string" }, + "fmt": { "type": "string" } + }, + "required": [ "event", "msg", "fmt" ] + } + ] + }, + + "cmd_path_event": { + "allOf": [ + { "$ref": "#/definitions/event_common_fields" }, + { + "properties": { + "event": { "const": "cmd_path" }, + "path": { "type": "string" } + }, + "required": [ "event", "path" ] + } + ] + }, + + "cmd_name_event": { + "allOf": [ + { "$ref": "#/definitions/event_common_fields" }, + { + "properties": { + "event": { "const": "cmd_name" }, + "name": { "type": "string" }, + "hierarchy": { "type": "string" } + }, + "required": [ "event", "name", "hierarchy" ] + } + ] + }, + + "cmd_mode_event": { + "allOf": [ + { "$ref": "#/definitions/event_common_fields" }, + { + "properties": { + "event": { "const": "cmd_mode" }, + "name": { "type": "string" } + }, + "required": [ "event", "name" ] + } + ] + }, + + "alias_event": { + "allOf": [ + { "$ref": "#/definitions/event_common_fields" }, + { + "properties": { + "event": { "const": "alias" }, + "alias": { "type": "string" }, + "argv": { + "type": "array", + "items": { "type": "string" } + } + }, + "required": [ "event", "alias", "argv" ] + } + ] + }, + + "child_start_event": { + "allOf": [ + { "$ref": "#/definitions/event_common_fields" }, + { + "properties": { + "event": { "const": "child_start" }, + "child_id": { "type": "integer" }, + "child_class": { "type": "string" }, + "use_shell": { "type": "boolean" }, + "argv": { + "type": "array", + "items": { "type": "string" } + }, + "hook_name": { "type": "string" }, + "cd": { "type": "string" } + }, + "required": [ + "event", "child_id", "child_class", "use_shell", "argv" + ] + } + ] + }, + + "child_exit_event": { + "allOf": [ + { "$ref": "#/definitions/event_common_fields" }, + { + "properties": { + "event": { "const": "child_exit" }, + "child_id": { "type": "integer" }, + "pid": { "type": "integer" }, + "code": { "type": "integer" }, + "t_rel": { "type": "number" } + }, + "required": [ "event", "child_id", "pid", "code", "t_rel" ] + } + ] + }, + + "exec_event": { + "allOf": [ + { "$ref": "#/definitions/event_common_fields" }, + { + "properties": { + "event": { "const": "exec" }, + "exec_id": { "type": "integer" }, + "exe": { "type": "string" }, + "argv": { + "type": "array", + "items": { "type": "string" } + } + }, + "required": [ "event", "exec_id", "exe", "argv" ] + } + ] + }, + + "exec_result_event": { + "allOf": [ + { "$ref": "#/definitions/event_common_fields" }, + { + "properties": { + "event": { "const": "exec_result" }, + "exec_id": { "type": "integer" }, + "code": { "type": "integer" } + }, + "required": [ "event", "exec_id", "code" ] + } + ] + }, + + "thread_start_event": { + "allOf": [ + { "$ref": "#/definitions/event_common_fields" }, + { + "properties": { + "event": { "const": "thread_start" }, + "thread": { "type": "string" } + }, + "required": [ "event", "thread" ] + } + ] + }, + + "thread_exit_event": { + "allOf": [ + { "$ref": "#/definitions/event_common_fields" }, + { + "properties": { + "event": { "const": "thread_exit" }, + "thread": { "type": "string" }, + "t_rel": { "type": "number" } + }, + "required": [ "event", "thread", "t_rel" ] + } + ] + }, + + "def_param_event": { + "allOf": [ + { "$ref": "#/definitions/event_common_fields" }, + { + "properties": { + "event": { "const": "def_param" }, + "param": { "type": "string" }, + "value": { "type": "string" } + }, + "required": [ "event", "param", "value" ] + } + ] + }, + + "def_repo_event": { + "allOf": [ + { "$ref": "#/definitions/event_common_fields" }, + { + "properties": { + "event": { "const": "def_repo" }, + "repo": { "type": "integer" }, + "worktree": { "type": "string" } + }, + "required": [ "event", "repo", "worktree" ] + } + ] + }, + + "region_enter_event": { + "allOf": [ + { "$ref": "#/definitions/event_common_fields" }, + { + "properties": { + "event": { "const": "region_enter" }, + "repo": { "type": "integer" }, + "nesting": { "type": "integer" }, + "category": { "type": "string" }, + "label": { "type": "string" }, + "msg": { "type": "string" } + }, + "required": [ "event", "nesting" ] + } + ] + }, + + "region_leave_event": { + "allOf": [ + { "$ref": "#/definitions/event_common_fields" }, + { + "properties": { + "event": { "const": "region_leave" }, + "repo": { "type": "integer" }, + "t_rel": { "type": "number" }, + "nesting": { "type": "integer" }, + "category": { "type": "string" }, + "label": { "type": "string" }, + "msg": { "type": "string" } + }, + "required": [ "event", "t_rel", "nesting" ] + } + ] + }, + + "data_event": { + "allOf": [ + { "$ref": "#/definitions/event_common_fields" }, + { + "properties": { + "event": { "const": "data" }, + "repo": { "type": "integer" }, + "t_abs": { "type": "number" }, + "t_rel": { "type": "number" }, + "nesting": { "type": "integer" }, + "category": { "type": "string" }, + "key": { "type": "string" }, + "value": { "type": "string" } + }, + "required": [ + "event", "t_abs", "t_rel", "nesting", "category", "key", + "value" + ] + } + ] + }, + + "data-json_event": { + "allOf": [ + { "$ref": "#/definitions/event_common_fields" }, + { + "properties": { + "event": { "const": "data-json" }, + "repo": { "type": "integer" }, + "t_abs": { "type": "number" }, + "t_rel": { "type": "number" }, + "nesting": { "type": "integer" }, + "category": { "type": "string" }, + "key": { "type": "string" }, + "value": { "type": "object" } + }, + "required": [ + "event", "t_abs", "t_rel", "nesting", "category", "key", + "value" + ] + } + ] + } + }, + + "type": "array", + "items": { + "oneOf": [ + { "$ref": "#/definitions/version_event" }, + { "$ref": "#/definitions/start_event" }, + { "$ref": "#/definitions/exit_event" }, + { "$ref": "#/definitions/atexit_event" }, + { "$ref": "#/definitions/signal_event" }, + { "$ref": "#/definitions/error_event" }, + { "$ref": "#/definitions/cmd_path_event" }, + { "$ref": "#/definitions/cmd_name_event" }, + { "$ref": "#/definitions/cmd_mode_event" }, + { "$ref": "#/definitions/alias_event" }, + { "$ref": "#/definitions/child_start_event" }, + { "$ref": "#/definitions/child_exit_event" }, + { "$ref": "#/definitions/exec_event" }, + { "$ref": "#/definitions/exec_result_event" }, + { "$ref": "#/definitions/thread_start_event" }, + { "$ref": "#/definitions/thread_exit_event" }, + { "$ref": "#/definitions/def_param_event" }, + { "$ref": "#/definitions/def_repo_event" }, + { "$ref": "#/definitions/region_enter_event" }, + { "$ref": "#/definitions/region_leave_event" }, + { "$ref": "#/definitions/data_event" }, + { "$ref": "#/definitions/data-json_event" } + ] + } +} diff --git a/t/trace_schema_validator/strict_list_schema.json b/t/trace_schema_validator/strict_list_schema.json new file mode 100644 index 0000000000..9a87baba0b --- /dev/null +++ b/t/trace_schema_validator/strict_list_schema.json @@ -0,0 +1,514 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$id": "http://git-scm.com/schemas/event_schema.json", + "title": "trace2 strict schema", + "description": "Strict schema for trace2 event output that verifies there are no unexpected fields.", + + "definitions": { + "version_event": { + "type": "object", + "properties": { + "sid": { "type": "string" }, + "thread": { "type": "string" }, + "time": { + "type": "string", + "format": "date-time" + }, + "file": { "type": "string" }, + "line": { "type": "integer" }, + "repo": { "type": "integer" }, + "event": { "const": "version" }, + "evt": { "const": "1" }, + "exe": { "type": "string" } + }, + "required": [ "sid", "thread", "event", "evt", "exe" ], + "additionalProperties": false + }, + + "start_event": { + "type": "object", + "properties": { + "sid": { "type": "string" }, + "thread": { "type": "string" }, + "time": { + "type": "string", + "format": "date-time" + }, + "file": { "type": "string" }, + "line": { "type": "integer" }, + "repo": { "type": "integer" }, + "event": { "const": "start" }, + "t_abs": { "type": "number" }, + "argv": { + "type": "array", + "items": { "type": "string" } + } + }, + "required": [ "sid", "thread", "time", "event", "t_abs", "argv" ], + "additionalProperties": false + }, + + "exit_event": { + "type": "object", + "properties": { + "sid": { "type": "string" }, + "thread": { "type": "string" }, + "time": { + "type": "string", + "format": "date-time" + }, + "file": { "type": "string" }, + "line": { "type": "integer" }, + "repo": { "type": "integer" }, + "event": { "const": "exit" }, + "t_abs": { "type": "number" }, + "code": { "type": "integer" } + }, + "required": [ "sid", "thread", "event", "t_abs", "code" ], + "additionalProperties": false + }, + + "atexit_event": { + "type": "object", + "properties": { + "sid": { "type": "string" }, + "thread": { "type": "string" }, + "time": { + "type": "string", + "format": "date-time" + }, + "file": { "type": "string" }, + "line": { "type": "integer" }, + "repo": { "type": "integer" }, + "event": { "const": "atexit" }, + "t_abs": { "type": "number" }, + "code": { "type": "integer" } + }, + "required": [ "sid", "thread", "time", "event", "t_abs", "code" ], + "additionalProperties": false + }, + + "signal_event": { + "type": "object", + "properties": { + "sid": { "type": "string" }, + "thread": { "type": "string" }, + "time": { + "type": "string", + "format": "date-time" + }, + "file": { "type": "string" }, + "line": { "type": "integer" }, + "repo": { "type": "integer" }, + "event": { "const": "signal" }, + "t_abs": { "type": "number" }, + "signo": { "type": "integer" } + }, + "required": [ "sid", "thread", "event", "t_abs", "signo" ], + "additionalProperties": false + }, + + "error_event": { + "type": "object", + "properties": { + "sid": { "type": "string" }, + "thread": { "type": "string" }, + "time": { + "type": "string", + "format": "date-time" + }, + "file": { "type": "string" }, + "line": { "type": "integer" }, + "repo": { "type": "integer" }, + "event": { "const": "error" }, + "msg": { "type": "string" }, + "fmt": { "type": "string" } + }, + "required": [ "sid", "thread", "event", "msg", "fmt" ], + "additionalProperties": false + }, + + "cmd_path_event": { + "type": "object", + "properties": { + "sid": { "type": "string" }, + "thread": { "type": "string" }, + "time": { + "type": "string", + "format": "date-time" + }, + "file": { "type": "string" }, + "line": { "type": "integer" }, + "repo": { "type": "integer" }, + "event": { "const": "cmd_path" }, + "path": { "type": "string" } + }, + "required": [ "sid", "thread", "event", "path" ], + "additionalProperties": false + }, + + "cmd_name_event": { + "type": "object", + "properties": { + "sid": { "type": "string" }, + "thread": { "type": "string" }, + "time": { + "type": "string", + "format": "date-time" + }, + "file": { "type": "string" }, + "line": { "type": "integer" }, + "repo": { "type": "integer" }, + "event": { "const": "cmd_name" }, + "name": { "type": "string" }, + "hierarchy": { "type": "string" } + }, + "required": [ "sid", "thread", "event", "name", "hierarchy" + ], + "additionalProperties": false + }, + + "cmd_mode_event": { + "type": "object", + "properties": { + "sid": { "type": "string" }, + "thread": { "type": "string" }, + "time": { + "type": "string", + "format": "date-time" + }, + "file": { "type": "string" }, + "line": { "type": "integer" }, + "repo": { "type": "integer" }, + "event": { "const": "cmd_mode" }, + "name": { "type": "string" } + }, + "required": [ "sid", "thread", "event", "name" ], + "additionalProperties": false + }, + + "alias_event": { + "type": "object", + "properties": { + "sid": { "type": "string" }, + "thread": { "type": "string" }, + "time": { + "type": "string", + "format": "date-time" + }, + "file": { "type": "string" }, + "line": { "type": "integer" }, + "repo": { "type": "integer" }, + "event": { "const": "alias" }, + "alias": { "type": "string" }, + "argv": { + "type": "array", + "items": { "type": "string" } + } + }, + "required": [ "sid", "thread", "event", "alias", "argv" ], + "additionalProperties": false + }, + + "child_start_event": { + "type": "object", + "properties": { + "sid": { "type": "string" }, + "thread": { "type": "string" }, + "time": { + "type": "string", + "format": "date-time" + }, + "file": { "type": "string" }, + "line": { "type": "integer" }, + "repo": { "type": "integer" }, + "event": { "const": "child_start" }, + "child_id": { "type": "integer" }, + "child_class": { "type": "string" }, + "use_shell": { "type": "boolean" }, + "argv": { + "type": "array", + "items": { "type": "string" } + }, + "hook_name": { "type": "string" }, + "cd": { "type": "string" } + }, + "required": [ + "sid", "thread", "event", "child_id", "child_class", + "use_shell", "argv" + ], + "additionalProperties": false + }, + + "child_exit_event": { + "type": "object", + "properties": { + "sid": { "type": "string" }, + "thread": { "type": "string" }, + "time": { + "type": "string", + "format": "date-time" + }, + "file": { "type": "string" }, + "line": { "type": "integer" }, + "repo": { "type": "integer" }, + "event": { "const": "child_exit" }, + "child_id": { "type": "integer" }, + "pid": { "type": "integer" }, + "code": { "type": "integer" }, + "t_rel": { "type": "number" } + }, + "required": [ + "sid", "thread", "event", "child_id", "pid", "code", "t_rel" + ], + "additionalProperties": false + }, + + "exec_event": { + "type": "object", + "properties": { + "sid": { "type": "string" }, + "thread": { "type": "string" }, + "time": { + "type": "string", + "format": "date-time" + }, + "file": { "type": "string" }, + "line": { "type": "integer" }, + "repo": { "type": "integer" }, + "event": { "const": "exec" }, + "exec_id": { "type": "integer" }, + "exe": { "type": "string" }, + "argv": { + "type": "array", + "items": { "type": "string" } + } + }, + "required": [ "sid", "thread", "event", "exec_id", "exe", "argv" ], + "additionalProperties": false + }, + + "exec_result_event": { + "type": "object", + "properties": { + "sid": { "type": "string" }, + "thread": { "type": "string" }, + "time": { + "type": "string", + "format": "date-time" + }, + "file": { "type": "string" }, + "line": { "type": "integer" }, + "repo": { "type": "integer" }, + "event": { "const": "exec_result" }, + "exec_id": { "type": "integer" }, + "code": { "type": "integer" } + }, + "required": [ "sid", "thread", "event", "exec_id", "code" ], + "additionalProperties": false + }, + + "thread_start_event": { + "type": "object", + "properties": { + "sid": { "type": "string" }, + "thread": { "type": "string" }, + "time": { + "type": "string", + "format": "date-time" + }, + "file": { "type": "string" }, + "line": { "type": "integer" }, + "repo": { "type": "integer" }, + "event": { "const": "thread_start" } + }, + "required": [ "sid", "thread", "event" ], + "additionalProperties": false + }, + + "thread_exit_event": { + "type": "object", + "properties": { + "sid": { "type": "string" }, + "thread": { "type": "string" }, + "time": { + "type": "string", + "format": "date-time" + }, + "file": { "type": "string" }, + "line": { "type": "integer" }, + "repo": { "type": "integer" }, + "event": { "const": "thread_exit" }, + "t_rel": { "type": "number" } + }, + "required": [ "sid", "thread", "event", "t_rel" ], + "additionalProperties": false + }, + + "def_param_event": { + "type": "object", + "properties": { + "sid": { "type": "string" }, + "thread": { "type": "string" }, + "time": { + "type": "string", + "format": "date-time" + }, + "file": { "type": "string" }, + "line": { "type": "integer" }, + "repo": { "type": "integer" }, + "event": { "const": "def_param" }, + "param": { "type": "string" }, + "value": { "type": "string" } + }, + "required": [ "sid", "thread", "event", "param", "value" ], + "additionalProperties": false + }, + + "def_repo_event": { + "type": "object", + "properties": { + "sid": { "type": "string" }, + "thread": { "type": "string" }, + "time": { + "type": "string", + "format": "date-time" + }, + "file": { "type": "string" }, + "line": { "type": "integer" }, + "repo": { "type": "integer" }, + "event": { "const": "def_repo" }, + "worktree": { "type": "string" } + }, + "required": [ "sid", "thread", "event", "repo", "worktree" ], + "additionalProperties": false + }, + + "region_enter_event": { + "type": "object", + "properties": { + "sid": { "type": "string" }, + "thread": { "type": "string" }, + "time": { + "type": "string", + "format": "date-time" + }, + "file": { "type": "string" }, + "line": { "type": "integer" }, + "repo": { "type": "integer" }, + "event": { "const": "region_enter" }, + "nesting": { "type": "integer" }, + "category": { "type": "string" }, + "label": { "type": "string" }, + "msg": { "type": "string" } + }, + "required": [ "sid", "thread", "event", "nesting" ], + "additionalProperties": false + }, + + "region_leave_event": { + "type": "object", + "properties": { + "sid": { "type": "string" }, + "thread": { "type": "string" }, + "time": { + "type": "string", + "format": "date-time" + }, + "file": { "type": "string" }, + "line": { "type": "integer" }, + "repo": { "type": "integer" }, + "event": { "const": "region_leave" }, + "t_rel": { "type": "number" }, + "nesting": { "type": "integer" }, + "category": { "type": "string" }, + "label": { "type": "string" }, + "msg": { "type": "string" } + }, + "required": [ "sid", "thread", "event", "t_rel", "nesting" ], + "additionalProperties": false + }, + + "data_event": { + "type": "object", + "properties": { + "sid": { "type": "string" }, + "thread": { "type": "string" }, + "time": { + "type": "string", + "format": "date-time" + }, + "file": { "type": "string" }, + "line": { "type": "integer" }, + "repo": { "type": "integer" }, + "event": { "const": "data" }, + "t_abs": { "type": "number" }, + "t_rel": { "type": "number" }, + "nesting": { "type": "integer" }, + "category": { "type": "string" }, + "key": { "type": "string" }, + "value": { "type": "string" } + }, + "required": [ + "sid", "thread", "event", "t_abs", "t_rel", "nesting", + "category","key", "value" + ], + "additionalProperties": false + }, + + "data-json_event": { + "type": "object", + "properties": { + "sid": { "type": "string" }, + "thread": { "type": "string" }, + "time": { + "type": "string", + "format": "date-time" + }, + "file": { "type": "string" }, + "line": { "type": "integer" }, + "repo": { "type": "integer" }, + "event": { "const": "data-json" }, + "t_abs": { "type": "number" }, + "t_rel": { "type": "number" }, + "nesting": { "type": "integer" }, + "category": { "type": "string" }, + "key": { "type": "string" }, + "value": { "type": "object" } + }, + "required": [ + "sid", "thread", "event", "t_abs", "t_rel", "nesting", + "category", "key", "value" + ], + "additionalProperties": false + } + }, + + "type": "array", + "items": { + "oneOf": [ + { "$ref": "#/definitions/version_event" }, + { "$ref": "#/definitions/start_event" }, + { "$ref": "#/definitions/exit_event" }, + { "$ref": "#/definitions/atexit_event" }, + { "$ref": "#/definitions/signal_event" }, + { "$ref": "#/definitions/error_event" }, + { "$ref": "#/definitions/cmd_path_event" }, + { "$ref": "#/definitions/cmd_name_event" }, + { "$ref": "#/definitions/cmd_mode_event" }, + { "$ref": "#/definitions/alias_event" }, + { "$ref": "#/definitions/child_start_event" }, + { "$ref": "#/definitions/child_exit_event" }, + { "$ref": "#/definitions/exec_event" }, + { "$ref": "#/definitions/exec_result_event" }, + { "$ref": "#/definitions/thread_start_event" }, + { "$ref": "#/definitions/thread_exit_event" }, + { "$ref": "#/definitions/def_param_event" }, + { "$ref": "#/definitions/def_repo_event" }, + { "$ref": "#/definitions/region_enter_event" }, + { "$ref": "#/definitions/region_leave_event" }, + { "$ref": "#/definitions/data_event" }, + { "$ref": "#/definitions/data-json_event" } + ] + } +} diff --git a/t/trace_schema_validator/strict_schema.json b/t/trace_schema_validator/strict_schema.json new file mode 100644 index 0000000000..b1addc7955 --- /dev/null +++ b/t/trace_schema_validator/strict_schema.json @@ -0,0 +1,511 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "$id": "http://git-scm.com/schemas/event_schema.json", + "title": "trace2 strict schema", + "description": "Strict schema for trace2 event output that verifies there are no unexpected fields.", + + "definitions": { + "version_event": { + "type": "object", + "properties": { + "sid": { "type": "string" }, + "thread": { "type": "string" }, + "time": { + "type": "string", + "format": "date-time" + }, + "file": { "type": "string" }, + "line": { "type": "integer" }, + "repo": { "type": "integer" }, + "event": { "const": "version" }, + "evt": { "const": "1" }, + "exe": { "type": "string" } + }, + "required": [ "sid", "thread", "event", "evt", "exe" ], + "additionalProperties": false + }, + + "start_event": { + "type": "object", + "properties": { + "sid": { "type": "string" }, + "thread": { "type": "string" }, + "time": { + "type": "string", + "format": "date-time" + }, + "file": { "type": "string" }, + "line": { "type": "integer" }, + "repo": { "type": "integer" }, + "event": { "const": "start" }, + "t_abs": { "type": "number" }, + "argv": { + "type": "array", + "items": { "type": "string" } + } + }, + "required": [ "sid", "thread", "time", "event", "t_abs", "argv" ], + "additionalProperties": false + }, + + "exit_event": { + "type": "object", + "properties": { + "sid": { "type": "string" }, + "thread": { "type": "string" }, + "time": { + "type": "string", + "format": "date-time" + }, + "file": { "type": "string" }, + "line": { "type": "integer" }, + "repo": { "type": "integer" }, + "event": { "const": "exit" }, + "t_abs": { "type": "number" }, + "code": { "type": "integer" } + }, + "required": [ "sid", "thread", "event", "t_abs", "code" ], + "additionalProperties": false + }, + + "atexit_event": { + "type": "object", + "properties": { + "sid": { "type": "string" }, + "thread": { "type": "string" }, + "time": { + "type": "string", + "format": "date-time" + }, + "file": { "type": "string" }, + "line": { "type": "integer" }, + "repo": { "type": "integer" }, + "event": { "const": "atexit" }, + "t_abs": { "type": "number" }, + "code": { "type": "integer" } + }, + "required": [ "sid", "thread", "time", "event", "t_abs", "code" ], + "additionalProperties": false + }, + + "signal_event": { + "type": "object", + "properties": { + "sid": { "type": "string" }, + "thread": { "type": "string" }, + "time": { + "type": "string", + "format": "date-time" + }, + "file": { "type": "string" }, + "line": { "type": "integer" }, + "repo": { "type": "integer" }, + "event": { "const": "signal" }, + "t_abs": { "type": "number" }, + "signo": { "type": "integer" } + }, + "required": [ "sid", "thread", "event", "t_abs", "signo" ], + "additionalProperties": false + }, + + "error_event": { + "type": "object", + "properties": { + "sid": { "type": "string" }, + "thread": { "type": "string" }, + "time": { + "type": "string", + "format": "date-time" + }, + "file": { "type": "string" }, + "line": { "type": "integer" }, + "repo": { "type": "integer" }, + "event": { "const": "error" }, + "msg": { "type": "string" }, + "fmt": { "type": "string" } + }, + "required": [ "sid", "thread", "event", "msg", "fmt" ], + "additionalProperties": false + }, + + "cmd_path_event": { + "type": "object", + "properties": { + "sid": { "type": "string" }, + "thread": { "type": "string" }, + "time": { + "type": "string", + "format": "date-time" + }, + "file": { "type": "string" }, + "line": { "type": "integer" }, + "repo": { "type": "integer" }, + "event": { "const": "cmd_path" }, + "path": { "type": "string" } + }, + "required": [ "sid", "thread", "event", "path" ], + "additionalProperties": false + }, + + "cmd_name_event": { + "type": "object", + "properties": { + "sid": { "type": "string" }, + "thread": { "type": "string" }, + "time": { + "type": "string", + "format": "date-time" + }, + "file": { "type": "string" }, + "line": { "type": "integer" }, + "repo": { "type": "integer" }, + "event": { "const": "cmd_name" }, + "name": { "type": "string" }, + "hierarchy": { "type": "string" } + }, + "required": [ "sid", "thread", "event", "name", "hierarchy" + ], + "additionalProperties": false + }, + + "cmd_mode_event": { + "type": "object", + "properties": { + "sid": { "type": "string" }, + "thread": { "type": "string" }, + "time": { + "type": "string", + "format": "date-time" + }, + "file": { "type": "string" }, + "line": { "type": "integer" }, + "repo": { "type": "integer" }, + "event": { "const": "cmd_mode" }, + "name": { "type": "string" } + }, + "required": [ "sid", "thread", "event", "name" ], + "additionalProperties": false + }, + + "alias_event": { + "type": "object", + "properties": { + "sid": { "type": "string" }, + "thread": { "type": "string" }, + "time": { + "type": "string", + "format": "date-time" + }, + "file": { "type": "string" }, + "line": { "type": "integer" }, + "repo": { "type": "integer" }, + "event": { "const": "alias" }, + "alias": { "type": "string" }, + "argv": { + "type": "array", + "items": { "type": "string" } + } + }, + "required": [ "sid", "thread", "event", "alias", "argv" ], + "additionalProperties": false + }, + + "child_start_event": { + "type": "object", + "properties": { + "sid": { "type": "string" }, + "thread": { "type": "string" }, + "time": { + "type": "string", + "format": "date-time" + }, + "file": { "type": "string" }, + "line": { "type": "integer" }, + "repo": { "type": "integer" }, + "event": { "const": "child_start" }, + "child_id": { "type": "integer" }, + "child_class": { "type": "string" }, + "use_shell": { "type": "boolean" }, + "argv": { + "type": "array", + "items": { "type": "string" } + }, + "hook_name": { "type": "string" }, + "cd": { "type": "string" } + }, + "required": [ + "sid", "thread", "event", "child_id", "child_class", + "use_shell", "argv" + ], + "additionalProperties": false + }, + + "child_exit_event": { + "type": "object", + "properties": { + "sid": { "type": "string" }, + "thread": { "type": "string" }, + "time": { + "type": "string", + "format": "date-time" + }, + "file": { "type": "string" }, + "line": { "type": "integer" }, + "repo": { "type": "integer" }, + "event": { "const": "child_exit" }, + "child_id": { "type": "integer" }, + "pid": { "type": "integer" }, + "code": { "type": "integer" }, + "t_rel": { "type": "number" } + }, + "required": [ + "sid", "thread", "event", "child_id", "pid", "code", "t_rel" + ], + "additionalProperties": false + }, + + "exec_event": { + "type": "object", + "properties": { + "sid": { "type": "string" }, + "thread": { "type": "string" }, + "time": { + "type": "string", + "format": "date-time" + }, + "file": { "type": "string" }, + "line": { "type": "integer" }, + "repo": { "type": "integer" }, + "event": { "const": "exec" }, + "exec_id": { "type": "integer" }, + "exe": { "type": "string" }, + "argv": { + "type": "array", + "items": { "type": "string" } + } + }, + "required": [ "sid", "thread", "event", "exec_id", "exe", "argv" ], + "additionalProperties": false + }, + + "exec_result_event": { + "type": "object", + "properties": { + "sid": { "type": "string" }, + "thread": { "type": "string" }, + "time": { + "type": "string", + "format": "date-time" + }, + "file": { "type": "string" }, + "line": { "type": "integer" }, + "repo": { "type": "integer" }, + "event": { "const": "exec_result" }, + "exec_id": { "type": "integer" }, + "code": { "type": "integer" } + }, + "required": [ "sid", "thread", "event", "exec_id", "code" ], + "additionalProperties": false + }, + + "thread_start_event": { + "type": "object", + "properties": { + "sid": { "type": "string" }, + "thread": { "type": "string" }, + "time": { + "type": "string", + "format": "date-time" + }, + "file": { "type": "string" }, + "line": { "type": "integer" }, + "repo": { "type": "integer" }, + "event": { "const": "thread_start" } + }, + "required": [ "sid", "thread", "event" ], + "additionalProperties": false + }, + + "thread_exit_event": { + "type": "object", + "properties": { + "sid": { "type": "string" }, + "thread": { "type": "string" }, + "time": { + "type": "string", + "format": "date-time" + }, + "file": { "type": "string" }, + "line": { "type": "integer" }, + "repo": { "type": "integer" }, + "event": { "const": "thread_exit" }, + "t_rel": { "type": "number" } + }, + "required": [ "sid", "thread", "event", "t_rel" ], + "additionalProperties": false + }, + + "def_param_event": { + "type": "object", + "properties": { + "sid": { "type": "string" }, + "thread": { "type": "string" }, + "time": { + "type": "string", + "format": "date-time" + }, + "file": { "type": "string" }, + "line": { "type": "integer" }, + "repo": { "type": "integer" }, + "event": { "const": "def_param" }, + "param": { "type": "string" }, + "value": { "type": "string" } + }, + "required": [ "sid", "thread", "event", "param", "value" ], + "additionalProperties": false + }, + + "def_repo_event": { + "type": "object", + "properties": { + "sid": { "type": "string" }, + "thread": { "type": "string" }, + "time": { + "type": "string", + "format": "date-time" + }, + "file": { "type": "string" }, + "line": { "type": "integer" }, + "repo": { "type": "integer" }, + "event": { "const": "def_repo" }, + "worktree": { "type": "string" } + }, + "required": [ "sid", "thread", "event", "repo", "worktree" ], + "additionalProperties": false + }, + + "region_enter_event": { + "type": "object", + "properties": { + "sid": { "type": "string" }, + "thread": { "type": "string" }, + "time": { + "type": "string", + "format": "date-time" + }, + "file": { "type": "string" }, + "line": { "type": "integer" }, + "repo": { "type": "integer" }, + "event": { "const": "region_enter" }, + "nesting": { "type": "integer" }, + "category": { "type": "string" }, + "label": { "type": "string" }, + "msg": { "type": "string" } + }, + "required": [ "sid", "thread", "event", "nesting" ], + "additionalProperties": false + }, + + "region_leave_event": { + "type": "object", + "properties": { + "sid": { "type": "string" }, + "thread": { "type": "string" }, + "time": { + "type": "string", + "format": "date-time" + }, + "file": { "type": "string" }, + "line": { "type": "integer" }, + "repo": { "type": "integer" }, + "event": { "const": "region_leave" }, + "t_rel": { "type": "number" }, + "nesting": { "type": "integer" }, + "category": { "type": "string" }, + "label": { "type": "string" }, + "msg": { "type": "string" } + }, + "required": [ "sid", "thread", "event", "t_rel", "nesting" ], + "additionalProperties": false + }, + + "data_event": { + "type": "object", + "properties": { + "sid": { "type": "string" }, + "thread": { "type": "string" }, + "time": { + "type": "string", + "format": "date-time" + }, + "file": { "type": "string" }, + "line": { "type": "integer" }, + "repo": { "type": "integer" }, + "event": { "const": "data" }, + "t_abs": { "type": "number" }, + "t_rel": { "type": "number" }, + "nesting": { "type": "integer" }, + "category": { "type": "string" }, + "key": { "type": "string" }, + "value": { "type": "string" } + }, + "required": [ + "sid", "thread", "event", "t_abs", "t_rel", "nesting", + "category","key", "value" + ], + "additionalProperties": false + }, + + "data-json_event": { + "type": "object", + "properties": { + "sid": { "type": "string" }, + "thread": { "type": "string" }, + "time": { + "type": "string", + "format": "date-time" + }, + "file": { "type": "string" }, + "line": { "type": "integer" }, + "repo": { "type": "integer" }, + "event": { "const": "data-json" }, + "t_abs": { "type": "number" }, + "t_rel": { "type": "number" }, + "nesting": { "type": "integer" }, + "category": { "type": "string" }, + "key": { "type": "string" }, + "value": { "type": "object" } + }, + "required": [ + "sid", "thread", "event", "t_abs", "t_rel", "nesting", + "category", "key", "value" + ], + "additionalProperties": false + } + }, + + "oneOf": [ + { "$ref": "#/definitions/version_event" }, + { "$ref": "#/definitions/start_event" }, + { "$ref": "#/definitions/exit_event" }, + { "$ref": "#/definitions/atexit_event" }, + { "$ref": "#/definitions/signal_event" }, + { "$ref": "#/definitions/error_event" }, + { "$ref": "#/definitions/cmd_path_event" }, + { "$ref": "#/definitions/cmd_name_event" }, + { "$ref": "#/definitions/cmd_mode_event" }, + { "$ref": "#/definitions/alias_event" }, + { "$ref": "#/definitions/child_start_event" }, + { "$ref": "#/definitions/child_exit_event" }, + { "$ref": "#/definitions/exec_event" }, + { "$ref": "#/definitions/exec_result_event" }, + { "$ref": "#/definitions/thread_start_event" }, + { "$ref": "#/definitions/thread_exit_event" }, + { "$ref": "#/definitions/def_param_event" }, + { "$ref": "#/definitions/def_repo_event" }, + { "$ref": "#/definitions/region_enter_event" }, + { "$ref": "#/definitions/region_leave_event" }, + { "$ref": "#/definitions/data_event" }, + { "$ref": "#/definitions/data-json_event" } + ] +} From patchwork Wed Jul 24 23:06:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Steadmon X-Patchwork-Id: 11057693 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AEF43138D for ; Wed, 24 Jul 2019 23:07:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9E83A28931 for ; Wed, 24 Jul 2019 23:07:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9282828936; Wed, 24 Jul 2019 23:07:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 117B928931 for ; Wed, 24 Jul 2019 23:07:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729676AbfGXXHE (ORCPT ); Wed, 24 Jul 2019 19:07:04 -0400 Received: from mail-vs1-f74.google.com ([209.85.217.74]:52173 "EHLO mail-vs1-f74.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726388AbfGXXHE (ORCPT ); Wed, 24 Jul 2019 19:07:04 -0400 Received: by mail-vs1-f74.google.com with SMTP id b7so12837918vsr.18 for ; Wed, 24 Jul 2019 16:07:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to; bh=HO7kB+uy+Vzh0iVuy0nkOYga1YzKJIrnasDVCbbacxI=; b=FqKY0QRdQMDr5cmyB4HS4MCJ9k/nd6VdnmeRQ/Z8byQ1qlc7ZPftjdXW7yv25qO5tU hSZcThS2dbiVNiK29vpj0hXRrgFgBfnobrAKs1ZUSDUvtBT3V7c0PQX4Q1mf+pk+1Lfm 5R9Qs1tww8cir5M5n1UywKto8IVcJqKrRky8cs+OzAIUy2Smplc8PoXs7GuKXQxOkV/Y FVxg/jQeszeSFgmWuXRJ2yGiqrnYW0ZF5r3UAblSPOPoY1Lqmq/50l3GrKhg/nXniVsX KRqcveWcTikYqGzUYHSH8nt0ZzjG8uYD9v5pNKUU3dBZiNXm9n6oJ1FMGUdj+nucNfIz y7aQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to; bh=HO7kB+uy+Vzh0iVuy0nkOYga1YzKJIrnasDVCbbacxI=; b=dBTdb9XFX4RGfToRIEPyhck1ZzU9UpqcR5b74nPSNpugckVFyAssir+uWhrxnHpjHH XVGefvTupXAhUXBS8ZvmmLWuZYQDc5HIKZE40USfLXu9Q3BNZWKKwylmQunAxUPByFhP RoLiwQlpnpU7igjmgpze2ujltncJ0o3m7qXlQTySVX5/bPuL5HGG3Fid5HklfUqPvjBa atCLw/TWaAhWLsrZ746v2aeDsPIKx/cU2aoqKt7SvJU5GTloprbwyUX4ZuDgu7XRmkNT GmghvqPUFgaokPgndJ+0UTuxo0yW9Ta8Hkua82D8UAGqK/gdrvRo732zJJG5CEGrntZi J/Dg== X-Gm-Message-State: APjAAAXDkeYMibS2uTCfSNS2JjtBNSWL22febDoAYbWoiuzdrAJ5uFf5 s6L6j3wh0eP1qPvIH0uk0mpWf5SHEKB0s3YmAAhFYq8fp3GBjkVQMmemLtDO8BYPksQHT/qId2V njRq/vJSkDaiZ7ZJqL93ANR25fnt3hzLVX7qEAjTI9XiYO6wtykJ7tJWNE4xJEIw= X-Google-Smtp-Source: APXvYqwyOpXb5t3Y1D6joYRo7uFKyDww1SGh6hJORqUxiyZ5RDAYpuqOQRWcrW56nBaiBpucAsvAUbgrxhjuFQ== X-Received: by 2002:a1f:5cd:: with SMTP id 196mr33400331vkf.62.1564009622675; Wed, 24 Jul 2019 16:07:02 -0700 (PDT) Date: Wed, 24 Jul 2019 16:06:52 -0700 In-Reply-To: Message-Id: <97cb6a3eb4f6c3f21fcdb69a15b0885c03526beb.1564009259.git.steadmon@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.22.0.709.g102302147b-goog Subject: [PATCH v3 2/3] trace2: add a schema validator for trace2 events From: Josh Steadmon To: git@vger.kernel.org, gitster@pobox.com, git@jeffhostetler.com, avarab@gmail.com, peff@peff.net, jnareb@gmail.com Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP trace_schema_validator can be used to verify that trace2 event output conforms to the expectations set by the API documentation and codified in event_schema.json (or strict_schema.json). This allows us to build a regression test to verify that trace2 output does not change unexpectedly. Signed-off-by: Josh Steadmon --- t/trace_schema_validator/.gitignore | 1 + t/trace_schema_validator/Makefile | 18 ++++ .../trace_schema_validator.go | 82 +++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 t/trace_schema_validator/.gitignore create mode 100644 t/trace_schema_validator/Makefile create mode 100644 t/trace_schema_validator/trace_schema_validator.go diff --git a/t/trace_schema_validator/.gitignore b/t/trace_schema_validator/.gitignore new file mode 100644 index 0000000000..c3f1e04e9e --- /dev/null +++ b/t/trace_schema_validator/.gitignore @@ -0,0 +1 @@ +trace_schema_validator diff --git a/t/trace_schema_validator/Makefile b/t/trace_schema_validator/Makefile new file mode 100644 index 0000000000..50bd266518 --- /dev/null +++ b/t/trace_schema_validator/Makefile @@ -0,0 +1,18 @@ +RM = rm -f +PROGRAMS = trace_schema_validator +GOCMD = go +GOBUILD = $(GOCMD) build +GOGET = $(GOCMD) get + +.PHONY: fetch_deps clean + +all: $(PROGRAMS) + +trace_schema_validator: fetch_deps trace_schema_validator.go + $(GOBUILD) -o trace_schema_validator + +fetch_deps: + $(GOGET) github.com/xeipuuv/gojsonschema + +clean: + $(RM) $(PROGRAMS) diff --git a/t/trace_schema_validator/trace_schema_validator.go b/t/trace_schema_validator/trace_schema_validator.go new file mode 100644 index 0000000000..bfda3c405e --- /dev/null +++ b/t/trace_schema_validator/trace_schema_validator.go @@ -0,0 +1,82 @@ +// trace_schema_validator validates individual lines of an input file against a +// provided JSON-Schema for git trace2 event output. +// +// Note that this expects each object to validate to be on its own line in the +// input file (AKA JSON-Lines format). This is what Git natively writes with +// GIT_TRACE2_EVENT enabled. +// +// Traces can be collected by setting the GIT_TRACE2_EVENT environment variable +// to an absolute path and running any Git command; traces will be appended to +// the file. +// +// Traces can then be verified like so: +// trace_schema_validator \ +// --trace2-event-file /path/to/trace/output \ +// --schema-file /path/to/schema +package main + +import ( + "bufio" + "flag" + "log" + "os" + "path/filepath" + + "github.com/xeipuuv/gojsonschema" +) + +// Required flags +var schemaFile = flag.String("schema-file", "", "JSON-Schema filename") +var trace2EventFile = flag.String("trace2-event-file", "", "trace2 event filename") +var progress = flag.Int("progress", 0, "Print progress message each time we have validated this many lines. --progress=0 means no messages are printed") + +func main() { + flag.Parse() + if *schemaFile == "" || *trace2EventFile == "" { + log.Fatal("Both --schema-file and --trace2-event-file are required.") + } + schemaURI, err := filepath.Abs(*schemaFile) + if err != nil { + log.Fatal("Can't get absolute path for schema file: ", err) + } + schemaURI = "file://" + schemaURI + + schemaLoader := gojsonschema.NewReferenceLoader(schemaURI) + schema, err := gojsonschema.NewSchema(schemaLoader) + if err != nil { + log.Fatal("Problem loading schema: ", err) + } + + tracesFile, err := os.Open(*trace2EventFile) + if err != nil { + log.Fatal("Problem opening trace file: ", err) + } + defer tracesFile.Close() + + scanner := bufio.NewScanner(tracesFile) + + count := 0 + for ; scanner.Scan(); count++ { + if *progress != 0 && count%*progress == 0 { + log.Print("Validated items: ", count) + } + event := gojsonschema.NewStringLoader(scanner.Text()) + result, err := schema.Validate(event) + if err != nil { + log.Fatal(err) + } + if !result.Valid() { + log.Printf("Trace event line %d is invalid: %s", count+1, scanner.Text()) + for _, desc := range result.Errors() { + log.Print("- ", desc) + } + os.Exit(1) + } + } + + if err := scanner.Err(); err != nil { + log.Fatal("Scanning error: ", err) + } + + log.Print("Validated events: ", count) +} From patchwork Wed Jul 24 23:06:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Steadmon X-Patchwork-Id: 11057697 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5762D14F6 for ; Wed, 24 Jul 2019 23:07:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 475222892A for ; Wed, 24 Jul 2019 23:07:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3BCA228932; Wed, 24 Jul 2019 23:07:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E05F728931 for ; Wed, 24 Jul 2019 23:07:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729679AbfGXXHG (ORCPT ); Wed, 24 Jul 2019 19:07:06 -0400 Received: from mail-pg1-f201.google.com ([209.85.215.201]:56374 "EHLO mail-pg1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726388AbfGXXHG (ORCPT ); Wed, 24 Jul 2019 19:07:06 -0400 Received: by mail-pg1-f201.google.com with SMTP id h5so29313998pgq.23 for ; Wed, 24 Jul 2019 16:07:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to; bh=epdg1RkjPfSeOFnpJAwwZ+NvLq1FWWjtkuy12AzRRYk=; b=WamYz3mOYY6E8ETIxAotJRQQzzb1jDnlqvuR/lUeeDhVkKzRZP8hG2O0XD9RDcRC3B Zn4CSSmVM2Pga0n7DrDhyz6M1Yv2yv7Ya8WT3ACu7vgJrJ1NQQ9GYtSm3ZVIV7Fy7c52 /dAiUDytnvEVP2HDgenNILqMM+vrEGJKx+4JYAWf0t5K8dRMTJNCEaszK5B8lL0nqQbB bhDGHwONn2XR563YboMsyxqa2EeSDeN6jWtSwGFECs1cfObBpfANljxEK0pOgpaJZaog zpsxelK3HnC4obpQy1jcb254AB6CL9CzOMF1bRuGgIHyPtY1pn+6qNcUsOIesYYvagbn dTqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to; bh=epdg1RkjPfSeOFnpJAwwZ+NvLq1FWWjtkuy12AzRRYk=; b=EYWB4WOLU3Pw2WsPRzKdXbAhAJT/z5JcWS2nR7nl2b2Wh1oOpBeDEyaAqCuq+NmPJ+ s+1P5bSQYZ7TviSsxZQSmJi3SleWnugnDLHCEKMGa/FxFt8RWSImy9nxWqWPXLmrADtB OVgl5UqPc6qt0ftEfJPXcwCXKmuq0CPREhUK2MpOUtrdkapCbHITxqOlxBZLX79w+x0U bfxoix4+oWQDPFkhkTihQWjM0eG7yk0G470Jnv3W+EKkiIIJ46120ef94HmnvuVWzPbF Ky2HOUokvUFe8vCeHfIbd8q4QDy10k8ao62OUqBJr6XlbjEDlirFU9O22AfYz/P+MdHW gzcg== X-Gm-Message-State: APjAAAU5ctPWrWzzr0G/11GpFvTIhk7Xp2p0m9DaUbCQ5dX4EygNjajl Z4T9ap0+6PybOBCqoSvuTIHFwOttyu2XK7KId27kx/hsQctLG0IETb3/HL3m3v5dBo5G7Vhig3m deWroh9vW41o7KFMxghtR3gdhPoeIMqAzE3RGN6LPooH4uj/SKzrp0bcLPuoJP/o= X-Google-Smtp-Source: APXvYqwrLI0dYRuwiednhiLp637z5MvM7yGlhBSO9HFz17sh53ob2RJvvaQO9Rr5+rigd8u6Zj4HKy9t4zZZew== X-Received: by 2002:a65:6102:: with SMTP id z2mr82763955pgu.391.1564009625082; Wed, 24 Jul 2019 16:07:05 -0700 (PDT) Date: Wed, 24 Jul 2019 16:06:53 -0700 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.22.0.709.g102302147b-goog Subject: [PATCH v3 3/3] ci: run trace2 schema validation in the CI suite From: Josh Steadmon To: git@vger.kernel.org, gitster@pobox.com, git@jeffhostetler.com, avarab@gmail.com, peff@peff.net, jnareb@gmail.com Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Josh Steadmon --- ci/run-build-and-tests.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ci/run-build-and-tests.sh b/ci/run-build-and-tests.sh index cdd2913440..ec38bf379a 100755 --- a/ci/run-build-and-tests.sh +++ b/ci/run-build-and-tests.sh @@ -14,6 +14,8 @@ make make test if test "$jobname" = "linux-gcc" then + make -C t/trace_schema_validator + export GIT_TRACE2_EVENT=$(mktemp) export GIT_TEST_SPLIT_INDEX=yes export GIT_TEST_FULL_IN_PACK_ARRAY=true export GIT_TEST_OE_SIZE=10 @@ -21,6 +23,10 @@ then export GIT_TEST_COMMIT_GRAPH=1 export GIT_TEST_MULTI_PACK_INDEX=1 make test + t/trace_schema_validator/trace_schema_validator \ + --trace2_event_file=${GIT_TRACE2_EVENT} \ + --schema_file=t/trace_schema_validator/strict_schema.json \ + --progress=10000 fi check_unignored_build_artifacts