Skip to content

Add more GA workflows #10

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

Merged
merged 1 commit into from
Nov 20, 2024
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
16 changes: 16 additions & 0 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: macOS

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:
runs-on: macos-latest

steps:
- uses: actions/checkout@v4
- name: make check
run: make check
34 changes: 34 additions & 0 deletions .github/workflows/msvc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: msvc

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:
runs-on: windows-latest
strategy:
matrix:
include:
- { msvc: Visual Studio 17 2022, arch: x64, config: Release }

steps:
- uses: actions/checkout@v4
with:
submodules: true

- name: Add MSBuild to PATH
uses: microsoft/[email protected]

- name: Configure CMake
run: |
cmake -B build -G "${{ matrix.msvc }}" -A ${{ matrix.arch }}

- name: Build
run: cmake --build build --config ${{ matrix.config }}

- name: Test
working-directory: build
run: ctest -C ${{ matrix.config }} --output-on-failure
32 changes: 32 additions & 0 deletions .github/workflows/msys2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: msys2

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:
runs-on: windows-latest

defaults:
run:
shell: msys2 {0}

steps:
- uses: actions/checkout@v4

- name: Setup MSYS2
uses: msys2/setup-msys2@v2
with:
msystem: mingw64
update: true
install: >-
git
make
mingw-w64-x86_64-gcc
mingw-w64-x86_64-toolchain

- name: make check
run: make check
44 changes: 42 additions & 2 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,51 @@ on:
branches: [ "main" ]

jobs:
build:

build-native:
# This job runs on x86_64 directly
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: make check
run: make check

build-other-arch:
# This job runs on other architectures via qemu
runs-on: ubuntu-latest

strategy:
matrix:
arch: [aarch64, ppc64le, s390x]
include:
- arch: aarch64
distro: ubuntu22.04
platform-name: linux/arm64
- arch: ppc64le
distro: ubuntu22.04
platform-name: linux/ppc64le
- arch: s390x
distro: ubuntu22.04
platform-name: linux/s390x

steps:
- uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: ${{ matrix.platform-name }}

- name: Build on ${{ matrix.arch }}
uses: uraimo/run-on-arch-action@v2
with:
arch: ${{ matrix.arch }}
distro: ${{ matrix.distro }}
githubToken: ${{ github.token }}

install: |
apt-get update
apt-get install -y make gcc g++

run: |
make check
47 changes: 47 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
cmake_minimum_required(VERSION 3.15)
project(jtjson)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Add double-conversion library
add_library(double-conversion STATIC
double-conversion/bignum.cc
double-conversion/bignum-dtoa.cc
double-conversion/cached-powers.cc
double-conversion/double-to-string.cc
double-conversion/fast-dtoa.cc
double-conversion/fixed-dtoa.cc
double-conversion/string-to-double.cc
double-conversion/strtod.cc
)
target_include_directories(double-conversion PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

# Main JSON library
add_library(json STATIC
json.cpp
)
target_link_libraries(json PRIVATE double-conversion)

# Tests
add_executable(json_test json_test.cpp)
target_link_libraries(json_test PRIVATE json)

add_executable(jsontestsuite_test jsontestsuite_test.cpp)
target_link_libraries(jsontestsuite_test PRIVATE json)

# Copy test data to build directory
add_custom_command(
TARGET jsontestsuite_test POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/JSONTestSuite
${CMAKE_CURRENT_BINARY_DIR}/JSONTestSuite
)

enable_testing()
add_test(NAME json_test COMMAND json_test)
add_test(
NAME jsontestsuite_test
COMMAND jsontestsuite_test
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
4 changes: 2 additions & 2 deletions json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ Bsr(int x)
static double
StringToDouble(const char* s, size_t n, int* out_processed)
{
if (n == -1ull)
if (n == (size_t)-1)
n = strlen(s);
int processed;
double res = kJsonToDouble.StringToDouble(s, n, &processed);
Expand Down Expand Up @@ -230,7 +230,7 @@ static char*
LongToString(char* p, long long x)
{
if (x < 0)
*p++ = '-', x = -(unsigned long long)x;
*p++ = '-', x = 0 - (unsigned long long)x;
return UlongToString(p, x);
}

Expand Down
38 changes: 8 additions & 30 deletions json_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@

#include "json.h"

#include <atomic>
#include <chrono>
#include <cstdio>
#include <cstdlib>
#include <time.h>

#define ARRAYLEN(A) \
((sizeof(A) / sizeof(*(A))) / ((unsigned)!(sizeof(A) % sizeof(*(A)))))
Expand Down Expand Up @@ -89,42 +90,19 @@ static const char kHuge[] = R"([

#define BENCH(ITERATIONS, WORK_PER_RUN, CODE) \
do { \
struct timespec start = now(); \
auto start = std::chrono::high_resolution_clock::now(); \
for (int __i = 0; __i < ITERATIONS; ++__i) { \
asm volatile("" ::: "memory"); \
std::atomic_signal_fence(std::memory_order_acq_rel); \
CODE; \
} \
auto end = std::chrono::high_resolution_clock::now(); \
auto duration = \
std::chrono::duration_cast<std::chrono::nanoseconds>(end - start); \
long long work = (WORK_PER_RUN) * (ITERATIONS); \
double nanos = (tonanos(tub(now(), start)) + work - 1) / (double)work; \
double nanos = (duration.count() + work - 1) / (double)work; \
printf("%10g ns %2dx %s\n", nanos, (ITERATIONS), #CODE); \
} while (0)

struct timespec
now(void)
{
struct timespec ts;
timespec_get(&ts, TIME_UTC);
return ts;
}

struct timespec
tub(struct timespec a, struct timespec b)
{
a.tv_sec -= b.tv_sec;
if (a.tv_nsec < b.tv_nsec) {
a.tv_nsec += 1000000000;
a.tv_sec--;
}
a.tv_nsec -= b.tv_nsec;
return a;
}

int64_t
tonanos(struct timespec x)
{
return x.tv_sec * 1000000000ull + x.tv_nsec;
}

void
object_test()
{
Expand Down
26 changes: 24 additions & 2 deletions jsontestsuite_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

#include <cstdio>
#include <cstdlib>
#include <unistd.h>

#define HI_RESET "\033[0m" // green
#define HI_GOOD "\033[32m" // green
Expand All @@ -28,6 +27,11 @@

using jt::Json;

#include "json.h"
#include <cstdio>
#include <cstdlib>
#include <string>

static const char* const kParsingTests[] = {
"i_number_double_huge_neg_exp.json",
"i_number_huge_exp.json",
Expand Down Expand Up @@ -349,6 +353,23 @@ static const char* const kParsingTests[] = {
"y_structure_whitespace_array.json",
};

const char*
get_test_path()
{
FILE* f = fopen("JSONTestSuite/test_parsing/y_array_empty.json", "rb");
if (f) {
fclose(f);
return "JSONTestSuite/test_parsing/";
}
f = fopen("../JSONTestSuite/test_parsing/y_array_empty.json", "rb");
if (f) {
fclose(f);
return "../JSONTestSuite/test_parsing/";
}
fprintf(stderr, "Could not find JSONTestSuite directory\n");
exit(1);
}

std::string
slurp(const char* path)
{
Expand All @@ -369,9 +390,10 @@ int
main()
{
int failures = 0;
std::string base_path = get_test_path();
int n = sizeof(kParsingTests) / sizeof(*kParsingTests);
for (int i = 0; i < n; ++i) {
std::string path = "JSONTestSuite/test_parsing/";
std::string path = base_path;
path += kParsingTests[i];
std::pair<Json::Status, Json> result = Json::parse(slurp(path.c_str()));
const char* color = "";
Expand Down
Loading
Loading