Repository navigation
conformance: add the suite generator, inspection and indexing files #1285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # The conformance suite is hashed byte for byte (tests/inputfiles/manifest.json); | ||
| # never convert its line endings on checkout. | ||
| *.jsonl -text | ||
| tests/inputfiles/manifest.json -text |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| #!/usr/bin/env bash | ||
| # Regenerates the conformance suite with the mkConformance binary given as | ||
| # the first argument and compares the discrete record files against the | ||
| # committed ones under tests/inputfiles. Files under floats/ are judged by | ||
| # the runners under tolerance and are not byte-compared: a compiler or libm | ||
| # change may legitimately move their last digit. See dev-docs/conformance.md. | ||
| # | ||
| # conformance_check.sh <path-to-mkConformance> [group-or-file]... | ||
| # | ||
| # Without groups, every group present in tests/inputfiles except digests is | ||
| # regenerated; digests takes minutes and is checked on a schedule instead. | ||
| set -eu | ||
|
|
||
| generator=$1 | ||
| shift | ||
| root=$(cd "$(dirname "$0")/.." && pwd) | ||
| committed="$root/tests/inputfiles" | ||
| out=$(mktemp -d) | ||
| trap 'rm -rf "$out"' EXIT | ||
|
|
||
| if [ $# -eq 0 ]; then | ||
| for dir in "$committed"/*/; do | ||
| group=$(basename "$dir") | ||
| if [ "$group" != digests ]; then | ||
| set -- "$@" "$group" | ||
| fi | ||
| done | ||
| fi | ||
|
|
||
| args=() | ||
| for group in "$@"; do | ||
| mkdir -p "$out/${group%%/*}" | ||
| args+=(-g "$group") | ||
| done | ||
|
|
||
| "$generator" -o "$out" "${args[@]}" | ||
|
|
||
| status=0 | ||
| for file in $(cd "$out" && find . -name '*.jsonl' | sort); do | ||
| file=${file#./} | ||
| case "$file" in | ||
| floats/*) continue ;; | ||
| esac | ||
| if ! cmp -s "$out/$file" "$committed/$file"; then | ||
| echo "conformance_check: $file differs from the committed file" >&2 | ||
| status=1 | ||
| fi | ||
| done | ||
|
|
||
| # A committed file the generator no longer writes is a difference too. | ||
| for group in "$@"; do | ||
| for path in "$committed/$group"/*.jsonl "$committed/$group"; do | ||
| [ -f "$path" ] || continue | ||
| file=${path#"$committed/"} | ||
| case "$file" in | ||
| floats/*) continue ;; | ||
| esac | ||
| if [ ! -f "$out/$file" ]; then | ||
| echo "conformance_check: $file is committed but was not regenerated" >&2 | ||
| status=1 | ||
| fi | ||
| done | ||
| done | ||
|
|
||
| if [ "$status" -eq 0 ]; then | ||
| echo "conformance_check: regenerated files match tests/inputfiles" | ||
| fi | ||
| exit "$status" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| /* | ||
| * Copyright 2026 Uber Technologies, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| /** @file conformance.h | ||
| * @brief Shared code for the conformance suite runners: reading record | ||
| * files, decoding the value conventions of dev-docs/conformance.md, and the | ||
| * comparison rules for sets, sequences, points and measures. | ||
| * | ||
| * A runner is a test app that takes one record file on the command line, | ||
| * calls `check` on each record and exits non-zero on the first record that | ||
| * does not match the library. Every failure names the file, the line and | ||
| * the key that differed, so that a line can be quoted as it is. | ||
| */ | ||
|
|
||
| #ifndef CONFORMANCE_H | ||
| #define CONFORMANCE_H | ||
|
|
||
| #include <stdbool.h> | ||
| #include <stdint.h> | ||
| #include <stdio.h> | ||
|
|
||
| #include "cJSON.h" | ||
| #include "h3api.h" | ||
|
|
||
| /** The specification version this runner implements. */ | ||
| #define CONFORMANCE_FORMAT "h3-conformance/1" | ||
| /** Angular tolerance on coordinates, in degrees of arc. */ | ||
| #define CONFORMANCE_ANGULAR_DEG 1e-12 | ||
| /** Relative tolerance on lengths and areas. */ | ||
| #define CONFORMANCE_RELATIVE 1e-9 | ||
|
|
||
| /** The units of a length or area output, for the tolerance floor. */ | ||
| typedef enum { | ||
| UNIT_RADS, | ||
| UNIT_KM, | ||
| UNIT_M, | ||
| UNIT_RADS2, | ||
| UNIT_KM2, | ||
| UNIT_M2 | ||
| } MeasureUnit; | ||
|
|
||
| /** A record file being read: a line at a time, each parsed as JSON. */ | ||
| typedef struct { | ||
| const char *path; | ||
| FILE *file; | ||
| char *line; | ||
| size_t capacity; | ||
| long lineNumber; | ||
| cJSON *record; | ||
| } ConformanceFile; | ||
|
|
||
| /** Opens a record file, exiting with a message on failure. */ | ||
| void conformanceOpen(ConformanceFile *f, const char *path); | ||
| /** Returns the next record, or NULL at end of file. The previous record is | ||
| * freed. A line that is not a JSON object is a failure. */ | ||
| cJSON *conformanceNext(ConformanceFile *f); | ||
| /** Frees the current record and closes the file. */ | ||
| void conformanceClose(ConformanceFile *f); | ||
|
|
||
| /** Prints the current file, line and record, then the message, and exits | ||
| * with status 1. */ | ||
| void conformanceFail(const char *format, ...); | ||
|
|
||
| /** Runs `check` on every record of the file named by argv[1] and returns the | ||
| * process exit status. */ | ||
| int conformanceMain(int argc, char *argv[], void (*check)(const cJSON *)); | ||
|
|
||
| /** Shorthand for a conformance assertion with a message. */ | ||
| #define c_assert(condition, message) \ | ||
| do { \ | ||
| if (!(condition)) { \ | ||
| conformanceFail("%s: %s", message, #condition); \ | ||
| } \ | ||
| } while (0) | ||
|
|
||
| /* JSON accessors. Each fails when the key is missing or has the wrong type, | ||
| * because every key of a group is present on every line. */ | ||
| cJSON *jsonItem(const cJSON *object, const char *key); | ||
| int jsonInt(const cJSON *object, const char *key); | ||
| int64_t jsonInt64(const cJSON *object, const char *key); | ||
| bool jsonBool(const cJSON *object, const char *key); | ||
| double jsonDouble(const cJSON *object, const char *key); | ||
| const char *jsonString(const cJSON *object, const char *key); | ||
| cJSON *jsonArray(const cJSON *object, const char *key); | ||
| /** Decodes a `[latitude, longitude]` pair in degrees to radians. */ | ||
| void jsonPoint(const cJSON *item, LatLng *out); | ||
|
|
||
| /** The H3Error enum name, as record files spell errors. */ | ||
| const char *errorName(H3Error err); | ||
| /** Whether an item is an error object, `{"err": "E_..."}`. */ | ||
| bool isErrorObject(const cJSON *item); | ||
| /** Compares a function's status with a result item. Returns true when the | ||
| * item is an error object, after checking the function failed with that | ||
| * error; returns false when the item is a value, after checking the function | ||
| * succeeded. `what` names the key in failure messages. */ | ||
| bool expectResult(const cJSON *item, H3Error got, const char *what); | ||
|
|
||
| /** Parses an index string and checks it formats back to the same string. */ | ||
| H3Index parseIndex(const char *text); | ||
| /** Formats an index the way record files do. */ | ||
| void formatIndex(H3Index h, char out[17]); | ||
| /** parseIndex on a key of an object. */ | ||
| H3Index jsonIndex(const cJSON *object, const char *key); | ||
| /** Parses an array of index strings into a malloc'd buffer. */ | ||
| H3Index *parseIndexArray(const cJSON *array, int64_t *count); | ||
|
|
||
| /** Checks an index against an index string item. */ | ||
| void assertIndex(const cJSON *item, H3Index got, const char *what); | ||
| /** Checks a set of indexes: both sides are sorted with zero padding and | ||
| * duplicates removed before comparison. `got` is reordered. */ | ||
| void assertIndexSet(const cJSON *array, H3Index *got, int64_t count, | ||
| const char *what); | ||
| /** Checks a sequence of indexes in order. */ | ||
| void assertIndexSequence(const cJSON *array, const H3Index *got, int64_t count, | ||
| const char *what); | ||
| /** Sorts indexes ascending, drops zeros and duplicates, returns the count. */ | ||
| int64_t normalizeIndexSet(H3Index *indexes, int64_t count); | ||
|
|
||
| /** Whether two points, in radians, are within the angular tolerance. */ | ||
| bool withinAngular(const LatLng *got, const LatLng *want); | ||
| /** Checks a point against a `[lat, lng]` item. */ | ||
| void assertPoint(const cJSON *item, const LatLng *got, const char *what); | ||
| /** Checks a sequence of points against an array of `[lat, lng]` items. */ | ||
| void assertPointSequence(const cJSON *array, const LatLng *got, int count, | ||
| const char *what); | ||
| /** Whether a measure is within the relative tolerance of the expected value | ||
| * or within the absolute floor for its unit. */ | ||
| bool withinMeasure(double got, double want, MeasureUnit unit); | ||
| /** Checks a measure, or its error, against a key of an object. */ | ||
| void assertMeasure(const cJSON *object, const char *key, H3Error err, | ||
| double got, MeasureUnit unit); | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /* | ||
| * Copyright 2026 Uber Technologies, Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| /** @file sha256.h | ||
| * @brief SHA-256 (FIPS 180-4), used to hash conformance suite files and | ||
| * digest streams. | ||
| */ | ||
|
|
||
| #ifndef SHA256_H | ||
| #define SHA256_H | ||
|
|
||
| #include <stddef.h> | ||
| #include <stdint.h> | ||
|
|
||
| /* Sha256 is a streaming SHA-256 state: the chaining value, the bytes not yet | ||
| * forming a block, and the total length. */ | ||
| typedef struct { | ||
| uint32_t state[8]; | ||
| uint8_t buffer[64]; | ||
| size_t buffered; | ||
| uint64_t total; | ||
| } Sha256; | ||
|
|
||
| /** Starts a digest. */ | ||
| void sha256Init(Sha256 *ctx); | ||
| /** Absorbs len bytes of data. */ | ||
| void sha256Update(Sha256 *ctx, const uint8_t *data, size_t len); | ||
| /** Finishes the digest and writes it as 64 lowercase hex characters plus a | ||
| * terminating NUL. The context must not be reused afterwards. */ | ||
| void sha256Final(Sha256 *ctx, char hex[65]); | ||
| /** Digests data in one call; see sha256Final for the output. */ | ||
| void sha256Hex(const uint8_t *data, size_t len, char hex[65]); | ||
|
|
||
| #endif |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.