Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions .github/workflows/clang-format-check.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,44 @@
name: clang-format Check
on: [push, pull_request]
name: CI / clang-format

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

on:
push:
branches: [ master ]
paths:
- '.clang-format'
- 'include/sonic/**'
- 'benchmark/**'
- 'tests/**'
- 'example/**'
- 'fuzz/**'
- '.github/workflows/clang-format-check.yml'
pull_request:
paths:
- '.clang-format'
- 'include/sonic/**'
- 'benchmark/**'
- 'tests/**'
- 'example/**'
- 'fuzz/**'
- '.github/workflows/clang-format-check.yml'
workflow_dispatch:

permissions:
contents: read

defaults:
run:
shell: bash

jobs:
formatting-check:
name: Formatting Check
name: clang-format
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
path:
- 'include/sonic'
Expand Down
22 changes: 17 additions & 5 deletions .github/workflows/test_arm.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
name: Test ARM
name: CI / Test (ARM)

permissions:
contents: read

defaults:
run:
shell: bash

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

on:
push:
Expand All @@ -10,12 +21,13 @@ on:
jobs:
test_arm:
runs-on: ubuntu-24.04-arm
timeout-minutes: 60
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y cmake ninja-build g++
sudo apt-get install -y --no-install-recommends cmake ninja-build g++
- name: Build and test NEON
run: |
cmake -S . -B build-neon -G Ninja
Expand All @@ -34,6 +46,6 @@ jobs:
- name: Build and test SVE2
if: steps.sve_check.outputs.supported == 'true'
run: |
cmake -S . -B build-sve -G Ninja -DENABLE_SVE2_128=ON -DENABLE_ASAN=OFF
cmake -S . -B build-sve -G Ninja -DENABLE_SVE2_128=ON
cmake --build build-sve
./build-sve/tests/unittest
ASAN_OPTIONS=detect_stack_use_after_return=0 ./build-sve/tests/unittest
33 changes: 30 additions & 3 deletions .github/workflows/test_coverage.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
# yaml-language-server: $schema=https://json-schema.org/draft-07/schema#
name: Test Coverage

permissions:
contents: read
actions: write
id-token: write

defaults:
run:
shell: bash

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

on:
push:
branches: [ master ]
pull_request:

jobs:
test-coverage:
name: bazel coverage
runs-on: ubuntu-24.04
timeout-minutes: 60
env:
GCC_VERSION: 12

Expand All @@ -16,21 +32,32 @@ jobs:
uses: actions/checkout@v4

- name: Read Bazel version
shell: bash
run: |
echo "BAZEL_VERSION=$(cat .bazelversion)" >> "$GITHUB_ENV"

- name: Cache Bazel
uses: actions/cache@v4
with:
path: |
~/.cache/bazel
~/.cache/bazelisk
key: ${{ runner.os }}-bazel-${{ env.BAZEL_VERSION }}-${{ hashFiles('MODULE.bazel.lock', 'WORKSPACE.bzlmod', 'BUILD.bazel') }}
restore-keys: |
${{ runner.os }}-bazel-${{ env.BAZEL_VERSION }}-
${{ runner.os }}-bazel-

- name: Setup bazel
uses: jwlawson/actions-setup-bazel@v2
with:
bazel-version: "${{ env.BAZEL_VERSION }}"

- name: Setup GCC
run: |
sudo apt-get install -y gcc-12 g++-12
sudo apt-get update
sudo apt-get install -y --no-install-recommends gcc-12 g++-12
- name: Install lcov
run: |
sudo apt install lcov
sudo apt-get install -y --no-install-recommends lcov

- name: Coverage
run: |
Expand Down
68 changes: 59 additions & 9 deletions .github/workflows/test_x86.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,43 @@
name: Test
on: [push, pull_request]
name: CI / Test (x86)

permissions:
contents: read
actions: write

defaults:
run:
shell: bash

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

on:
push:
branches: [ master ]
paths-ignore:
- 'docs/**'
- 'licenses/**'
- '**/*.md'
- 'Doxyfile'
- '.vscode/**'
pull_request:
workflow_dispatch:

jobs:
test-llvm:
name: clang ${{ matrix.llvm_version }} / ${{ matrix.tool }} / ${{ matrix.arch }}
runs-on: ubuntu-24.04
timeout-minutes: 45
strategy:
fail-fast: false
matrix:
llvm_version: ['11', '16.0.4', '17']
tool: ['cmake', 'bazel']
arch: [westmere, haswell]
exclude:
- tool: 'cmake'
arch: westmere
- tool: 'cmake'
arch: westmere
env:
CC: clang
CXX: clang++
Expand All @@ -22,10 +47,21 @@ jobs:

- name: Read Bazel version
if: matrix.tool == 'bazel'
shell: bash
run: |
echo "BAZEL_VERSION=$(cat .bazelversion)" >> "$GITHUB_ENV"

- name: Cache Bazel
if: matrix.tool == 'bazel'
uses: actions/cache@v4
with:
path: |
~/.cache/bazel
~/.cache/bazelisk
key: ${{ runner.os }}-bazel-${{ env.BAZEL_VERSION }}-${{ hashFiles('MODULE.bazel.lock', 'WORKSPACE.bzlmod', 'BUILD.bazel') }}
restore-keys: |
${{ runner.os }}-bazel-${{ env.BAZEL_VERSION }}-
${{ runner.os }}-bazel-

- name: Install LLVM and Clang
uses: KyleMayes/install-llvm-action@v2
with:
Expand All @@ -45,7 +81,7 @@ jobs:

- name: Run ${{ matrix.arch }} Test Use Bazel
if: matrix.tool == 'bazel'
run : |
run: |
bash ./scripts/unittest.sh -c --arch=${{ matrix.arch }}

- name: Run Test Use CMake
Expand All @@ -54,7 +90,9 @@ jobs:
bash ./scripts/run_cmake.sh

test-gcc:
name: gcc ${{ matrix.gcc_version }} / ${{ matrix.tool }} / ${{ matrix.arch }} / ${{ matrix.dispatch }}
runs-on: ubuntu-24.04
timeout-minutes: 60
strategy:
fail-fast: false
matrix:
Expand All @@ -80,13 +118,25 @@ jobs:

- name: Read Bazel version
if: matrix.tool == 'bazel'
shell: bash
run: |
echo "BAZEL_VERSION=$(cat .bazelversion)" >> "$GITHUB_ENV"

- name: Install GCC
run: |
sudo apt-get install -y gcc-${{ matrix.gcc_version }} g++-${{ matrix.gcc_version }}
sudo apt-get update
sudo apt-get install -y --no-install-recommends gcc-${{ matrix.gcc_version }} g++-${{ matrix.gcc_version }}

- name: Cache Bazel
if: matrix.tool == 'bazel'
uses: actions/cache@v4
with:
path: |
~/.cache/bazel
~/.cache/bazelisk
key: ${{ runner.os }}-bazel-${{ env.BAZEL_VERSION }}-${{ hashFiles('MODULE.bazel.lock', 'WORKSPACE.bzlmod', 'BUILD.bazel') }}
restore-keys: |
${{ runner.os }}-bazel-${{ env.BAZEL_VERSION }}-
${{ runner.os }}-bazel-

- name: Setup bazel
if: matrix.tool == 'bazel'
Expand All @@ -102,7 +152,7 @@ jobs:

- name: Run ${{ matrix.arch }} ${{ matrix.dispatch }} Test Use Bazel
if: matrix.tool == 'bazel'
run : |
run: |
bash ./scripts/unittest.sh -g --arch=${{ matrix.arch }} --dispatch=${{ matrix.dispatch }}

- name: Run Test Use CMake
Expand Down
67 changes: 58 additions & 9 deletions benchmark/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@

#include <benchmark/benchmark.h>

#include <cstdlib>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <sstream>
#include <string_view>
#include <system_error>
#include <vector>

#include "cjson.hpp"
#include "jsoncpp.hpp"
Expand All @@ -30,14 +33,50 @@
#include "sonic.hpp"
#include "yyjson.hpp"

static std::string get_json(const std::string_view file) {
std::ifstream ifs;
static std::string get_json(const std::filesystem::path &file) {
std::ifstream ifs(file, std::ios::in | std::ios::binary);
if (!ifs.is_open()) return {};

std::stringstream ss;
ifs.open(file.data());
ss << ifs.rdbuf();
return ss.str();
}

static void add_testdata_candidates(std::vector<std::filesystem::path> &out,
const std::filesystem::path &root) {
if (root.empty()) return;

out.push_back(root / "testdata");
out.push_back(root / "_main" / "testdata");

std::error_code ec;
if (!std::filesystem::is_directory(root, ec)) return;
for (const auto &e : std::filesystem::directory_iterator(root, ec)) {
if (e.is_directory(ec)) out.push_back(e.path() / "testdata");
}
}

static std::filesystem::path find_testdata_dir(const char *argv0) {
std::vector<std::filesystem::path> candidates;
candidates.emplace_back("testdata");

if (const char *p = std::getenv("RUNFILES_DIR"))
add_testdata_candidates(candidates, std::filesystem::path(p));
if (const char *p = std::getenv("TEST_SRCDIR"))
add_testdata_candidates(candidates, std::filesystem::path(p));

if (argv0 && *argv0) {
add_testdata_candidates(
candidates, std::filesystem::path(std::string(argv0) + ".runfiles"));
}

std::error_code ec;
for (const auto &c : candidates) {
if (std::filesystem::is_directory(c, ec)) return c;
}
return {};
}

template <typename Json, typename PR, typename SR>
static void BM_Encode(benchmark::State &state, std::string_view filename,
std::string_view data) {
Expand Down Expand Up @@ -173,7 +212,7 @@ static void BM_Decode(benchmark::State &state, std::string filename,
state.SetBytesProcessed(int64_t(state.iterations()) * int64_t(data.size()));
}

static void regitser_OnDemand() {
static void regitser_OnDemand(const std::filesystem::path &testdata_dir) {
std::vector<OnDemand> tests = {
{"twitter", "Normal", {"search_metadata", "count"}, 100, true},
{"citm_catalog",
Expand All @@ -185,7 +224,7 @@ static void regitser_OnDemand() {
};

for (auto &t : tests) {
auto file_path = std::string("testdata/") + t.file + ".json";
auto file_path = testdata_dir / (t.file + ".json");
t.json = get_json(file_path);

#define REG_ONDEMAND(JSON) \
Expand All @@ -203,14 +242,24 @@ static void regitser_OnDemand() {
int main(int argc, char **argv) {
benchmark::Initialize(&argc, argv);

auto testdata_dir = find_testdata_dir(argv[0]);
if (testdata_dir.empty()) {
std::cerr << "Cannot locate 'testdata' directory. Try running with Bazel "
"runfiles."
<< std::endl;
return 1;
}

// Read the data from json files
std::vector<std::pair<std::filesystem::path, std::string>> jsons;
for (const auto &entry : std::filesystem::directory_iterator("testdata"))
std::error_code ec;
for (const auto &entry :
std::filesystem::directory_iterator(testdata_dir, ec)) {
if (entry.path().extension() == ".json")
jsons.push_back(
std::make_pair(entry.path(), get_json(entry.path().string())));
jsons.push_back(std::make_pair(entry.path(), get_json(entry.path())));
}

regitser_OnDemand();
regitser_OnDemand(testdata_dir);
#define ADD_JSON_BMK(JSON, ACT) \
do { \
benchmark::RegisterBenchmark( \
Expand Down
Loading
Loading