Skip to content
Snippets Groups Projects
Commit b6696a10 authored by Kia's avatar Kia
Browse files

other files

parent 8a76eea2
No related branches found
No related tags found
No related merge requests found
Makefile 0 → 100755
CFLAGS= -Wall -pedantic -std=c11 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/home/thz/include -L/home/thz/lib -ggdb
LIBS= -lhammer -lglib-2.0
all: bug1 bug2 bug3
bug1: bug1.c
gcc $(CFLAGS) -o bug1 bug1.c $(LIBS)
bug2: bug2.c
gcc $(CFLAGS) -o bug2 bug2.c $(LIBS)
bug3: bug3.c
gcc $(CFLAGS) -o bug3 bug3.c $(LIBS)
run:
@echo "[Bug1]"
@./bug1 -k
@echo "[Bug2]"
@./bug2 -k
@echo "[Bug3]"
@./bug3 -k
clean:
rm -f bug1 bug2 bug3
README 0 → 100755
Here are 3 self-contained bug files. However, I believe that they may
all be the same bug in different guises.
All 3 parsers work with PB_MIN, but fail with PB_LALR.
See the constant BKEND to change between the two.
bug1.c uses:
H_RULE(int8range, h_int_range(h_int8(), -1, 1));
bug2.c uses:
/* parse a single int16 between the values of -2 and 1 */
H_RULE(bigint16, h_with_endianness(BYTE_BIG_ENDIAN,h_int16()));
H_RULE(int16range, h_int_range(bigint16,-2,1));
bug3.c uses:
/* parse a single int16 between the values of -2 and 1 */
H_RULE(littleint16, h_with_endianness(BYTE_LITTLE_ENDIAN,h_int16()));
H_RULE(int16range, h_int_range(littleint16,-2,1));
bug1.c 0 → 100755
/*
* bug1 -- h_int8() issues
*
* This parser passes all tests if the backend is PB_MIN but fails if
* the backend is PB_LALR.
*
* See defines for BKEND below.
*/
#include <glib.h>
#include <hammer/hammer.h>
#include <hammer/glue.h>
#include <hammer/test_suite.h>
#define BKEND PB_LALR
//#define BKEND PB_MIN
const HParser *pp; /* the parser */
uint8_t input[1024]; /* the input is a buff of bytes */
/* The Parser */
void init_parser() {
/* parse a single int8 between the values of -1 and 1 */
H_RULE(int8range, h_int_range(h_uint8(), -1, 1));
pp = h_sequence(int8range,h_end_p(),NULL);
}
/* Passing Tests: -1,0,+1 */
static void test_m1() {
input[0] = 0xFF; // -1
g_check_parse_ok(pp, BKEND, input, 1);
}
static void test_zero() {
input[0] = 0x00; // 0
g_check_parse_ok(pp, BKEND, input, 1);
}
static void test_p1() {
input[0] = 0x01; // +1
g_check_parse_ok(pp, BKEND, input, 1);
}
/* Failing Tests: -2,+2,+1+1 */
static void test_m2() {
input[0] = 0xFE; // -2
g_check_parse_failed(pp, BKEND, input, 1);
}
static void test_p2() {
input[0] = 0x02; // +2
g_check_parse_failed(pp, BKEND, input, 1);
}
static void test_2val() {
input[0] = 0x01; // +1
input[1] = 0x01; // +1
g_check_parse_failed(pp, BKEND, input, 2);
}
void register_bug_tests() {
g_test_add_func("/pass/neg1",test_m1);
g_test_add_func("/pass/zero",test_zero);
g_test_add_func("/pass/pos1",test_p1);
g_test_add_func("/fail/neg2",test_m2);
g_test_add_func("/fail/pos2",test_p2);
g_test_add_func("/fail/2val",test_2val);
}
int main(int argc, char *argv[]) {
init_parser();
g_test_init(&argc,&argv,NULL);
register_bug_tests();
return g_test_run();
}
bug2.c 0 → 100755
/*
* bug2 -- h_int16() issues using big endian
*
* This parser passes all tests if the backend is PB_MIN but fails if
* the backend is PB_LALR.
*
* See defines for BKEND below.
*/
#include <hammer/hammer.h>
#include <hammer/glue.h>
#include <hammer/test_suite.h>
#include <glib.h>
#define BKEND PB_LALR
//#define BKEND PB_MIN
const HParser *pp; /* the parser */
uint8_t input[1024]; /* the input is a buff of bytes */
/* The Parser */
void init_parser() {
/* parse a single int16 between the values of -2 and 1 */
H_RULE(bigint16, h_with_endianness(BYTE_BIG_ENDIAN,h_int16()));
H_RULE(int16range, h_int_range(bigint16,-2,1));
pp = h_sequence(int16range,h_end_p(),NULL);
}
/* Passing Tests: -2,-1,0,+1 */
static void test_n2() {
input[0] = 0xFF; // -2
input[1] = 0xFE; //
g_check_parse_ok(pp, BKEND, input, 2);
}
static void test_n1() {
input[0] = 0xFF; // -1
input[1] = 0xFF; //
g_check_parse_ok(pp, BKEND, input, 2);
}
static void test_zero() {
input[0] = 0x00; // 0
input[1] = 0x00; // 0
g_check_parse_ok(pp, BKEND, input, 2);
}
static void test_p1() {
input[0] = 0x00; // +1
input[1] = 0x01;
g_check_parse_ok(pp, BKEND, input, 2);
}
/* Failing Tests: -3,+2,+1+1 */
static void test_n3() {
input[0] = 0xFF; // -3
input[1] = 0xFD;
g_check_parse_failed(pp, BKEND, input, 2);
}
static void test_p2() {
input[0] = 0x00; // +2
input[1] = 0x02;
g_check_parse_failed(pp, BKEND, input, 2);
}
static void test_2val() {
input[0] = 0x00; // +1
input[1] = 0x01;
input[0] = 0x00; // +1
input[1] = 0x01;
g_check_parse_failed(pp, BKEND, input, 4);
}
void register_bug_tests() {
g_test_add_func("/pass/neg2",test_n2);
g_test_add_func("/pass/neg1",test_n1);
g_test_add_func("/pass/zero",test_zero);
g_test_add_func("/pass/pos1",test_p1);
g_test_add_func("/fail/neg3",test_n3);
g_test_add_func("/fail/pos2",test_p2);
g_test_add_func("/fail/2val",test_2val);
}
int main(int argc, char *argv[]) {
init_parser();
g_test_init(&argc,&argv,NULL);
register_bug_tests();
return g_test_run();
}
bug3.c 0 → 100755
/*
* bug3 -- h_int16() issues using little endian
*
* This parser passes all tests if the backend is PB_MIN but fails if
* the backend is PB_LALR.
*
* See defines for BKEND below.
*/
#include <hammer/hammer.h>
#include <hammer/glue.h>
#include <hammer/test_suite.h>
#include <glib.h>
#define BKEND PB_LALR
//#define BKEND PB_MIN
const HParser *pp; /* the parser */
uint8_t input[1024]; /* the input is a buff of bytes */
/* The Parser */
void init_parser() {
/* parse a single int16 between the values of -2 and 1 */
H_RULE(littleint16, h_with_endianness(BYTE_LITTLE_ENDIAN,h_int16()));
H_RULE(int16range, h_int_range(littleint16,-2,1));
pp = h_sequence(int16range,h_end_p(),NULL);
}
/* Passing Tests: -2,-1,0,+1 */
static void test_n2() {
input[0] = 0xFE; //
input[1] = 0xFF; // -2
g_check_parse_ok(pp, BKEND, input, 2);
}
static void test_n1() {
input[0] = 0xFF; //
input[1] = 0xFF; // -1
g_check_parse_ok(pp, BKEND, input, 2);
}
static void test_zero() {
input[0] = 0x00; // 0
input[1] = 0x00; // 0
g_check_parse_ok(pp, BKEND, input, 2);
}
static void test_p1() {
input[0] = 0x01;
input[1] = 0x00; // +1
g_check_parse_ok(pp, BKEND, input, 2);
}
/* Failing Tests: -3,+2,+1+1 */
static void test_n3() {
input[0] = 0xFD;
input[1] = 0xFF; // -3
g_check_parse_failed(pp, BKEND, input, 2);
}
static void test_p2() {
input[0] = 0x02;
input[1] = 0x00; // +2
g_check_parse_failed(pp, BKEND, input, 2);
}
static void test_2val() {
input[0] = 0x01;
input[1] = 0x00; // +1
input[0] = 0x01;
input[1] = 0x00; // +1
g_check_parse_failed(pp, BKEND, input, 4);
}
void register_bug_tests() {
g_test_add_func("/pass/neg2",test_n2);
g_test_add_func("/pass/neg1",test_n1);
g_test_add_func("/pass/zero",test_zero);
g_test_add_func("/pass/pos1",test_p1);
g_test_add_func("/fail/neg3",test_n3);
g_test_add_func("/fail/pos2",test_p2);
g_test_add_func("/fail/2val",test_2val);
}
int main(int argc, char *argv[]) {
init_parser();
g_test_init(&argc,&argv,NULL);
register_bug_tests();
return g_test_run();
}
span.c 0 → 100755
/*
* Integer-range parser combinator exhaustive test
*
*/
#include <hammer/hammer.h>
#include <hammer/glue.h>
#include <string.h>
#include <stdlib.h>
#define BKEND PB_LALR
//#define BKEND PB_MIN
HParser *int16_ranger(int16_t left, int16_t right) {
H_RULE(littleint16, h_with_endianness(BYTE_BIG_ENDIAN,h_int16()));
H_RULE(int16range, h_int_range(littleint16, left, right));
return h_sequence(int16range,h_end_p(),NULL);
}
int run_parse(HParser *parser, HParserBackend backend,
uint8_t *input, size_t input_len) {
assert(h_compile(parser, backend, NULL) == 0);
return h_parse(parser, input, input_len);
}
int main(int argc, char *argv[]) {
assert(argc == 3);
int16_t low = atoi(argv[1]);
int16_t high = atoi(argv[2]);
printf("%d %d\n", low, high);
HParser *pp = int16_ranger(low, high);
int16_t k;
for (k=INT16_MIN; k<INT16_MAX; k++) {
uint8_t tmp1[2], tmp2[2];
// if (0) {
// memcpy(tmp1, &k, 2);
// tmp2[0] = tmp1[1];
// tmp2[1] = tmp1[0];
// } else
// {
memcpy(tmp2, &k, 2);
// }
if(!run_parse(pp, BKEND, tmp2, 2)) {
printf("parse failed %d\n", k);
} else {
printf("parse success 0x%hx\n", k);
}
}
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment