Various formatting issues in the tests directory.

This commit is contained in:
Daniel Lemire 2019-06-26 19:48:51 -04:00
parent 9e79acc25a
commit 471c71310b
6 changed files with 70 additions and 58 deletions

View File

@ -105,8 +105,10 @@ int main(int argc, char *argv[]) {
rapid_correct_checkencoding ? "correct" : "invalid"); rapid_correct_checkencoding ? "correct" : "invalid");
printf("sajson : %s \n", printf("sajson : %s \n",
sajson_correct ? "correct" : "invalid"); sajson_correct ? "correct" : "invalid");
if(oursreturn == simdjson::DEPTH_ERROR) { if (oursreturn == simdjson::DEPTH_ERROR) {
printf("simdjson encountered a DEPTH_ERROR, it was parametrized to reject documents with depth exceeding %zu.\n", maxdepth); printf("simdjson encountered a DEPTH_ERROR, it was parametrized to "
"reject documents with depth exceeding %zu.\n",
maxdepth);
} }
if ((ours_correct != rapid_correct_checkencoding) || if ((ours_correct != rapid_correct_checkencoding) ||
(rapid_correct_checkencoding != sajson_correct) || (rapid_correct_checkencoding != sajson_correct) ||

View File

@ -15,10 +15,10 @@ bool skyprophet_test() {
std::vector<std::string> data; std::vector<std::string> data;
char buf[1024]; char buf[1024];
for (size_t i = 0; i < n_records; ++i) { for (size_t i = 0; i < n_records; ++i) {
auto n = sprintf(buf, auto n =
"{\"id\": %zu, \"name\": \"name%zu\", \"gender\": \"%s\", " sprintf(buf, "{\"id\": %zu, \"name\": \"name%zu\", \"gender\": \"%s\", "
"\"school\": {\"id\": %zu, \"name\": \"school%zu\"}}", "\"school\": {\"id\": %zu, \"name\": \"school%zu\"}}",
i, i, (i % 2) ? "male" : "female", i % 10, i % 10); i, i, (i % 2) ? "male" : "female", i % 10, i % 10);
data.emplace_back(std::string(buf, n)); data.emplace_back(std::string(buf, n));
} }
for (size_t i = 0; i < n_records; ++i) { for (size_t i = 0; i < n_records; ++i) {

View File

@ -31,7 +31,6 @@ bool contains(const char *pre, const char *str) {
return (strstr(str, pre) != nullptr); return (strstr(str, pre) != nullptr);
} }
bool validate(const char *dirname) { bool validate(const char *dirname) {
bool everythingfine = true; bool everythingfine = true;
const char *extension = ".json"; const char *extension = ".json";
@ -46,9 +45,10 @@ bool validate(const char *dirname) {
printf("nothing in dir %s \n", dirname); printf("nothing in dir %s \n", dirname);
return false; return false;
} }
bool * isfileasexpected = new bool[c]; bool *isfileasexpected = new bool[c];
for(int i = 0; i < c; i++) { isfileasexpected[i] = true; for (int i = 0; i < c; i++) {
} isfileasexpected[i] = true;
}
size_t howmany = 0; size_t howmany = 0;
bool needsep = (strlen(dirname) > 1) && (dirname[strlen(dirname) - 1] != '/'); bool needsep = (strlen(dirname) > 1) && (dirname[strlen(dirname) - 1] != '/');
for (int i = 0; i < c; i++) { for (int i = 0; i < c; i++) {
@ -68,47 +68,50 @@ bool validate(const char *dirname) {
padded_string p; padded_string p;
try { try {
get_corpus(fullpath).swap(p); get_corpus(fullpath).swap(p);
} catch (const std::exception& e) { } catch (const std::exception &e) {
std::cerr << "Could not load the file " << fullpath << std::endl; std::cerr << "Could not load the file " << fullpath << std::endl;
return EXIT_FAILURE; return EXIT_FAILURE;
} }
ParsedJson pj; ParsedJson pj;
bool allocok = pj.allocateCapacity(p.size(), 1024); bool allocok = pj.allocateCapacity(p.size(), 1024);
if(!allocok) { if (!allocok) {
std::cerr << "can't allocate memory"<<std::endl; std::cerr << "can't allocate memory" << std::endl;
return false; return false;
} }
++howmany; ++howmany;
const int parseRes = json_parse(p, pj); const int parseRes = json_parse(p, pj);
printf("%s\n", parseRes == 0 ? "ok" : "invalid"); printf("%s\n", parseRes == 0 ? "ok" : "invalid");
if(contains("EXCLUDE",name)) { if (contains("EXCLUDE", name)) {
// skipping // skipping
howmany--; howmany--;
} else if (startsWith("pass", name) && parseRes != 0) { } else if (startsWith("pass", name) && parseRes != 0) {
isfileasexpected[i] = false; isfileasexpected[i] = false;
printf("warning: file %s should pass but it fails. Error is: %s\n", name, simdjson::errorMsg(parseRes).data()); printf("warning: file %s should pass but it fails. Error is: %s\n",
everythingfine = false; name, simdjson::errorMsg(parseRes).data());
everythingfine = false;
} else if (startsWith("fail", name) && parseRes == 0) { } else if (startsWith("fail", name) && parseRes == 0) {
isfileasexpected[i] = false; isfileasexpected[i] = false;
printf("warning: file %s should fail but it passes.\n", name); printf("warning: file %s should fail but it passes.\n", name);
everythingfine = false; everythingfine = false;
} }
free(fullpath); free(fullpath);
} }
} }
printf("%zu files checked.\n", howmany); printf("%zu files checked.\n", howmany);
if(everythingfine) { if (everythingfine) {
printf("All ok!\n"); printf("All ok!\n");
} else { } else {
fprintf(stderr, "There were problems! Consider reviewing the following files:\n"); fprintf(stderr,
for(int i = 0; i < c; i++) { "There were problems! Consider reviewing the following files:\n");
if(!isfileasexpected[i]) { fprintf(stderr, "%s \n", entry_list[i]->d_name); for (int i = 0; i < c; i++) {
} if (!isfileasexpected[i]) {
fprintf(stderr, "%s \n", entry_list[i]->d_name);
}
} }
} }
for (int i = 0; i < c; ++i) { for (int i = 0; i < c; ++i) {
free(entry_list[i]); free(entry_list[i]);
} }
free(entry_list); free(entry_list);
delete[] isfileasexpected; delete[] isfileasexpected;
return everythingfine; return everythingfine;
@ -124,9 +127,8 @@ int main(int argc, char *argv[]) {
<< std::endl; << std::endl;
return validate("jsonchecker/") ? EXIT_SUCCESS : EXIT_FAILURE; return validate("jsonchecker/") ? EXIT_SUCCESS : EXIT_FAILURE;
#else #else
std::cout std::cout << "We are going to assume you mean to use the '"
<< "We are going to assume you mean to use the '"<< SIMDJSON_TEST_DATA_DIR <<"' directory." << SIMDJSON_TEST_DATA_DIR << "' directory." << std::endl;
<< std::endl;
return validate(SIMDJSON_TEST_DATA_DIR) ? EXIT_SUCCESS : EXIT_FAILURE; return validate(SIMDJSON_TEST_DATA_DIR) ? EXIT_SUCCESS : EXIT_FAILURE;
#endif #endif
} }

View File

@ -30,7 +30,8 @@ bool startsWith(const char *pre, const char *str) {
} }
bool is_in_bad_list(const char *buf) { bool is_in_bad_list(const char *buf) {
if(buf[0] != '0') return false; if (buf[0] != '0')
return false;
for (size_t i = 0; i < sizeof(really_bad) / sizeof(really_bad[0]); i++) for (size_t i = 0; i < sizeof(really_bad) / sizeof(really_bad[0]); i++)
if (startsWith(really_bad[i], buf)) if (startsWith(really_bad[i], buf))
return true; return true;
@ -68,19 +69,22 @@ inline void foundFloat(double result, const uint8_t *buf) {
float_count++; float_count++;
double expected = strtod((const char *)buf, &endptr); double expected = strtod((const char *)buf, &endptr);
if (endptr == (const char *)buf) { if (endptr == (const char *)buf) {
fprintf(stderr, "parsed %f from %.32s whereas strtod refuses to parse a float, ", fprintf(stderr,
result, buf); "parsed %f from %.32s whereas strtod refuses to parse a float, ",
result, buf);
fprintf(stderr, " while parsing %s \n", fullpath); fprintf(stderr, " while parsing %s \n", fullpath);
parse_error |= PARSE_ERROR; parse_error |= PARSE_ERROR;
} }
if( fpclassify(expected) != fpclassify(result) ) { if (fpclassify(expected) != fpclassify(result)) {
fprintf(stderr, "floats not in the same category expected: %f observed: %f \n", expected, result); fprintf(stderr,
"floats not in the same category expected: %f observed: %f \n",
expected, result);
fprintf(stderr, "%.32s\n", buf); fprintf(stderr, "%.32s\n", buf);
parse_error |= PARSE_ERROR; parse_error |= PARSE_ERROR;
} }
// we want to get some reasonable relative accuracy // we want to get some reasonable relative accuracy
else if (fabs(expected - result) > else if (fabs(expected - result) >
1e-14 * fmin(fabs(expected), fabs(result))) { 1e-14 * fmin(fabs(expected), fabs(result))) {
fprintf(stderr, "parsed %.128e from \n", result); fprintf(stderr, "parsed %.128e from \n", result);
fprintf(stderr, " %.32s whereas strtod gives\n", buf); fprintf(stderr, " %.32s whereas strtod gives\n", buf);
fprintf(stderr, " %.128e,", expected); fprintf(stderr, " %.128e,", expected);
@ -131,7 +135,7 @@ bool validate(const char *dirname) {
padded_string p; padded_string p;
try { try {
get_corpus(fullpath).swap(p); get_corpus(fullpath).swap(p);
} catch (const std::exception& e) { } catch (const std::exception &e) {
std::cout << "Could not load the file " << fullpath << std::endl; std::cout << "Could not load the file " << fullpath << std::endl;
return EXIT_FAILURE; return EXIT_FAILURE;
} }
@ -172,12 +176,14 @@ int main(int argc, char *argv[]) {
if (argc != 2) { if (argc != 2) {
std::cerr << "Usage: " << argv[0] << " <directorywithjsonfiles>" std::cerr << "Usage: " << argv[0] << " <directorywithjsonfiles>"
<< std::endl; << std::endl;
#if defined(SIMDJSON_TEST_DATA_DIR) && defined(SIMDJSON_BENCHMARK_DATA_DIR) #if defined(SIMDJSON_TEST_DATA_DIR) && defined(SIMDJSON_BENCHMARK_DATA_DIR)
std::cout std::cout << "We are going to assume you mean to use the '"
<< "We are going to assume you mean to use the '"<< SIMDJSON_TEST_DATA_DIR <<"' and '"<< SIMDJSON_BENCHMARK_DATA_DIR <<"'directories." << SIMDJSON_TEST_DATA_DIR << "' and '"
<< std::endl; << SIMDJSON_BENCHMARK_DATA_DIR << "'directories." << std::endl;
return validate(SIMDJSON_TEST_DATA_DIR) && validate(SIMDJSON_BENCHMARK_DATA_DIR) ? EXIT_SUCCESS return validate(SIMDJSON_TEST_DATA_DIR) &&
: EXIT_FAILURE; validate(SIMDJSON_BENCHMARK_DATA_DIR)
? EXIT_SUCCESS
: EXIT_FAILURE;
#else #else
std::cout << "We are going to assume you mean to use the 'jsonchecker' and " std::cout << "We are going to assume you mean to use the 'jsonchecker' and "
"'jsonexamples' directories." "'jsonexamples' directories."

View File

@ -1,14 +1,14 @@
#include <iostream>
#include "../singleheader/simdjson.h" #include "../singleheader/simdjson.h"
#include <iostream>
int main() { int main() {
const char * filename = JSON_TEST_PATH; const char *filename = JSON_TEST_PATH;
padded_string p = get_corpus(filename); padded_string p = get_corpus(filename);
ParsedJson pj = build_parsed_json(p); // do the parsing ParsedJson pj = build_parsed_json(p); // do the parsing
if( ! pj.isValid() ) { if (!pj.isValid()) {
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if( ! pj.allocateCapacity(p.size()) ) { if (!pj.allocateCapacity(p.size())) {
return EXIT_FAILURE; return EXIT_FAILURE;
} }
const int res = json_parse(p, pj); const int res = json_parse(p, pj);

View File

@ -2,11 +2,11 @@
#include <cstring> #include <cstring>
#include <dirent.h> #include <dirent.h>
#include <inttypes.h> #include <inttypes.h>
#include <iostream>
#include <math.h> #include <math.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <iostream>
#ifndef JSON_TEST_STRINGS #ifndef JSON_TEST_STRINGS
#define JSON_TEST_STRINGS #define JSON_TEST_STRINGS
@ -201,7 +201,7 @@ static bool parse_string(const char *p, char *output, char **end) {
} }
} }
// end of borrowed code // end of borrowed code
char * bigbuffer; // global variable char *bigbuffer; // global variable
inline void foundBadString(const uint8_t *buf) { inline void foundBadString(const uint8_t *buf) {
bad_string++; bad_string++;
@ -328,18 +328,18 @@ bool validate(const char *dirname) {
padded_string p; padded_string p;
try { try {
get_corpus(fullpath).swap(p); get_corpus(fullpath).swap(p);
} catch (const std::exception& e) { } catch (const std::exception &e) {
std::cout << "Could not load the file " << fullpath << std::endl; std::cout << "Could not load the file " << fullpath << std::endl;
return EXIT_FAILURE; return EXIT_FAILURE;
} }
ParsedJson pj; ParsedJson pj;
bool allocok = pj.allocateCapacity(p.size(), 1024); bool allocok = pj.allocateCapacity(p.size(), 1024);
if (!allocok) { if (!allocok) {
std::cerr << "can't allocate memory" << std::endl; std::cerr << "can't allocate memory" << std::endl;
return false; return false;
} }
bigbuffer = (char *) malloc(p.size()); bigbuffer = (char *)malloc(p.size());
if(bigbuffer == NULL) { if (bigbuffer == NULL) {
std::cerr << "can't allocate memory" << std::endl; std::cerr << "can't allocate memory" << std::endl;
return false; return false;
} }
@ -380,12 +380,14 @@ int main(int argc, char *argv[]) {
if (argc != 2) { if (argc != 2) {
std::cerr << "Usage: " << argv[0] << " <directorywithjsonfiles>" std::cerr << "Usage: " << argv[0] << " <directorywithjsonfiles>"
<< std::endl; << std::endl;
#if defined(SIMDJSON_TEST_DATA_DIR) && defined(SIMDJSON_BENCHMARK_DATA_DIR) #if defined(SIMDJSON_TEST_DATA_DIR) && defined(SIMDJSON_BENCHMARK_DATA_DIR)
std::cout std::cout << "We are going to assume you mean to use the '"
<< "We are going to assume you mean to use the '"<< SIMDJSON_TEST_DATA_DIR <<"' and '"<< SIMDJSON_BENCHMARK_DATA_DIR <<"'directories." << SIMDJSON_TEST_DATA_DIR << "' and '"
<< std::endl; << SIMDJSON_BENCHMARK_DATA_DIR << "'directories." << std::endl;
return validate(SIMDJSON_TEST_DATA_DIR) && validate(SIMDJSON_BENCHMARK_DATA_DIR) ? EXIT_SUCCESS return validate(SIMDJSON_TEST_DATA_DIR) &&
: EXIT_FAILURE; validate(SIMDJSON_BENCHMARK_DATA_DIR)
? EXIT_SUCCESS
: EXIT_FAILURE;
#else #else
std::cout << "We are going to assume you mean to use the 'jsonchecker' and " std::cout << "We are going to assume you mean to use the 'jsonchecker' and "
"'jsonexamples' directories." "'jsonexamples' directories."