Skip to content

Commit 936744c

Browse files
authored
Add more GA workflows (#10)
1 parent f8b3a3d commit 936744c

File tree

10 files changed

+219
-50
lines changed

10 files changed

+219
-50
lines changed

.github/workflows/macos.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: macOS
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
build:
11+
runs-on: macos-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
- name: make check
16+
run: make check

.github/workflows/msvc.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: msvc
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
build:
11+
runs-on: windows-latest
12+
strategy:
13+
matrix:
14+
include:
15+
- { msvc: Visual Studio 17 2022, arch: x64, config: Release }
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
with:
20+
submodules: true
21+
22+
- name: Add MSBuild to PATH
23+
uses: microsoft/[email protected]
24+
25+
- name: Configure CMake
26+
run: |
27+
cmake -B build -G "${{ matrix.msvc }}" -A ${{ matrix.arch }}
28+
29+
- name: Build
30+
run: cmake --build build --config ${{ matrix.config }}
31+
32+
- name: Test
33+
working-directory: build
34+
run: ctest -C ${{ matrix.config }} --output-on-failure

.github/workflows/msys2.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: msys2
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
build:
11+
runs-on: windows-latest
12+
13+
defaults:
14+
run:
15+
shell: msys2 {0}
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Setup MSYS2
21+
uses: msys2/setup-msys2@v2
22+
with:
23+
msystem: mingw64
24+
update: true
25+
install: >-
26+
git
27+
make
28+
mingw-w64-x86_64-gcc
29+
mingw-w64-x86_64-toolchain
30+
31+
- name: make check
32+
run: make check

.github/workflows/ubuntu.yml

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,51 @@ on:
77
branches: [ "main" ]
88

99
jobs:
10-
build:
11-
10+
build-native:
11+
# This job runs on x86_64 directly
1212
runs-on: ubuntu-latest
1313

1414
steps:
1515
- uses: actions/checkout@v4
1616
- name: make check
1717
run: make check
18+
19+
build-other-arch:
20+
# This job runs on other architectures via qemu
21+
runs-on: ubuntu-latest
22+
23+
strategy:
24+
matrix:
25+
arch: [aarch64, ppc64le, s390x]
26+
include:
27+
- arch: aarch64
28+
distro: ubuntu22.04
29+
platform-name: linux/arm64
30+
- arch: ppc64le
31+
distro: ubuntu22.04
32+
platform-name: linux/ppc64le
33+
- arch: s390x
34+
distro: ubuntu22.04
35+
platform-name: linux/s390x
36+
37+
steps:
38+
- uses: actions/checkout@v4
39+
40+
- name: Set up QEMU
41+
uses: docker/setup-qemu-action@v3
42+
with:
43+
platforms: ${{ matrix.platform-name }}
44+
45+
- name: Build on ${{ matrix.arch }}
46+
uses: uraimo/run-on-arch-action@v2
47+
with:
48+
arch: ${{ matrix.arch }}
49+
distro: ${{ matrix.distro }}
50+
githubToken: ${{ github.token }}
51+
52+
install: |
53+
apt-get update
54+
apt-get install -y make gcc g++
55+
56+
run: |
57+
make check

CMakeLists.txt

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
cmake_minimum_required(VERSION 3.15)
2+
project(jtjson)
3+
4+
set(CMAKE_CXX_STANDARD 11)
5+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
6+
7+
# Add double-conversion library
8+
add_library(double-conversion STATIC
9+
double-conversion/bignum.cc
10+
double-conversion/bignum-dtoa.cc
11+
double-conversion/cached-powers.cc
12+
double-conversion/double-to-string.cc
13+
double-conversion/fast-dtoa.cc
14+
double-conversion/fixed-dtoa.cc
15+
double-conversion/string-to-double.cc
16+
double-conversion/strtod.cc
17+
)
18+
target_include_directories(double-conversion PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
19+
20+
# Main JSON library
21+
add_library(json STATIC
22+
json.cpp
23+
)
24+
target_link_libraries(json PRIVATE double-conversion)
25+
26+
# Tests
27+
add_executable(json_test json_test.cpp)
28+
target_link_libraries(json_test PRIVATE json)
29+
30+
add_executable(jsontestsuite_test jsontestsuite_test.cpp)
31+
target_link_libraries(jsontestsuite_test PRIVATE json)
32+
33+
# Copy test data to build directory
34+
add_custom_command(
35+
TARGET jsontestsuite_test POST_BUILD
36+
COMMAND ${CMAKE_COMMAND} -E copy_directory
37+
${CMAKE_SOURCE_DIR}/JSONTestSuite
38+
${CMAKE_CURRENT_BINARY_DIR}/JSONTestSuite
39+
)
40+
41+
enable_testing()
42+
add_test(NAME json_test COMMAND json_test)
43+
add_test(
44+
NAME jsontestsuite_test
45+
COMMAND jsontestsuite_test
46+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
47+
)

json.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ Bsr(int x)
196196
static double
197197
StringToDouble(const char* s, size_t n, int* out_processed)
198198
{
199-
if (n == -1ull)
199+
if (n == (size_t)-1)
200200
n = strlen(s);
201201
int processed;
202202
double res = kJsonToDouble.StringToDouble(s, n, &processed);
@@ -230,7 +230,7 @@ static char*
230230
LongToString(char* p, long long x)
231231
{
232232
if (x < 0)
233-
*p++ = '-', x = -(unsigned long long)x;
233+
*p++ = '-', x = 0 - (unsigned long long)x;
234234
return UlongToString(p, x);
235235
}
236236

json_test.cpp

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717

1818
#include "json.h"
1919

20+
#include <atomic>
21+
#include <chrono>
2022
#include <cstdio>
2123
#include <cstdlib>
22-
#include <time.h>
2324

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

9091
#define BENCH(ITERATIONS, WORK_PER_RUN, CODE) \
9192
do { \
92-
struct timespec start = now(); \
93+
auto start = std::chrono::high_resolution_clock::now(); \
9394
for (int __i = 0; __i < ITERATIONS; ++__i) { \
94-
asm volatile("" ::: "memory"); \
95+
std::atomic_signal_fence(std::memory_order_acq_rel); \
9596
CODE; \
9697
} \
98+
auto end = std::chrono::high_resolution_clock::now(); \
99+
auto duration = \
100+
std::chrono::duration_cast<std::chrono::nanoseconds>(end - start); \
97101
long long work = (WORK_PER_RUN) * (ITERATIONS); \
98-
double nanos = (tonanos(tub(now(), start)) + work - 1) / (double)work; \
102+
double nanos = (duration.count() + work - 1) / (double)work; \
99103
printf("%10g ns %2dx %s\n", nanos, (ITERATIONS), #CODE); \
100104
} while (0)
101105

102-
struct timespec
103-
now(void)
104-
{
105-
struct timespec ts;
106-
timespec_get(&ts, TIME_UTC);
107-
return ts;
108-
}
109-
110-
struct timespec
111-
tub(struct timespec a, struct timespec b)
112-
{
113-
a.tv_sec -= b.tv_sec;
114-
if (a.tv_nsec < b.tv_nsec) {
115-
a.tv_nsec += 1000000000;
116-
a.tv_sec--;
117-
}
118-
a.tv_nsec -= b.tv_nsec;
119-
return a;
120-
}
121-
122-
int64_t
123-
tonanos(struct timespec x)
124-
{
125-
return x.tv_sec * 1000000000ull + x.tv_nsec;
126-
}
127-
128106
void
129107
object_test()
130108
{

jsontestsuite_test.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
#include <cstdio>
2121
#include <cstdlib>
22-
#include <unistd.h>
2322

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

2928
using jt::Json;
3029

30+
#include "json.h"
31+
#include <cstdio>
32+
#include <cstdlib>
33+
#include <string>
34+
3135
static const char* const kParsingTests[] = {
3236
"i_number_double_huge_neg_exp.json",
3337
"i_number_huge_exp.json",
@@ -349,6 +353,23 @@ static const char* const kParsingTests[] = {
349353
"y_structure_whitespace_array.json",
350354
};
351355

356+
const char*
357+
get_test_path()
358+
{
359+
FILE* f = fopen("JSONTestSuite/test_parsing/y_array_empty.json", "rb");
360+
if (f) {
361+
fclose(f);
362+
return "JSONTestSuite/test_parsing/";
363+
}
364+
f = fopen("../JSONTestSuite/test_parsing/y_array_empty.json", "rb");
365+
if (f) {
366+
fclose(f);
367+
return "../JSONTestSuite/test_parsing/";
368+
}
369+
fprintf(stderr, "Could not find JSONTestSuite directory\n");
370+
exit(1);
371+
}
372+
352373
std::string
353374
slurp(const char* path)
354375
{
@@ -369,9 +390,10 @@ int
369390
main()
370391
{
371392
int failures = 0;
393+
std::string base_path = get_test_path();
372394
int n = sizeof(kParsingTests) / sizeof(*kParsingTests);
373395
for (int i = 0; i < n; ++i) {
374-
std::string path = "JSONTestSuite/test_parsing/";
396+
std::string path = base_path;
375397
path += kParsingTests[i];
376398
std::pair<Json::Status, Json> result = Json::parse(slurp(path.c_str()));
377399
const char* color = "";

0 commit comments

Comments
 (0)