Permalink
Browse files

OS-1723 DTrace should speak JSON

Reviewed by: Bryan Cantrill <bmc@joyent.com>
  • Loading branch information...
jclulow committed Nov 27, 2012
1 parent ced3e32 commit 8017f1f8eea31bd1160b5e50755242a2a9aabc7d
@@ -26,6 +26,7 @@
#
# Copyright (c) 2012 by Delphix. All rights reserved.
# Copyright (c) 2012, Joyent, Inc. All rights reserved.
#
include $(SRC)/Makefile.master
@@ -71,6 +72,18 @@ pid/tst.gcc.exe: pid/tst.gcc.c
$(GCC) -o pid/tst.gcc.exe pid/tst.gcc.c $(LDFLAGS)
$(POST_PROCESS) ; $(STRIP_STABS)
json/tst.usdt.o: json/usdt.h
json/usdt.h: json/usdt.d
$(DTRACE) -h -s json/usdt.d -o json/usdt.h
json/usdt.o: json/usdt.d json/tst.usdt.o
$(COMPILE.d) -o json/usdt.o -s json/usdt.d json/tst.usdt.o
json/tst.usdt.exe: json/tst.usdt.o json/usdt.o
$(LINK.c) -o json/tst.usdt.exe json/tst.usdt.o json/usdt.o $(LDLIBS)
$(POST_PROCESS) ; $(STRIP_STABS)
usdt/tst.args.exe: usdt/tst.args.o usdt/args.o
$(LINK.c) -o usdt/tst.args.exe usdt/tst.args.o usdt/args.o $(LDLIBS)
$(POST_PROCESS) ; $(STRIP_STABS)
@@ -22,6 +22,7 @@
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
* Copyright (c) 2012, Joyent, Inc. All rights reserved.
*/
#include <sys/dtrace.h>
@@ -99,6 +100,8 @@ STRFUNC(inet_ntop(AF_INET, (void *)alloca(sizeof (ipaddr_t))))
STRFUNC(toupper("foo"))
STRFUNC(tolower("BAR"))
INTFUNC(getf(0))
INTFUNC(strtoll("0x12EE5D5", 16))
STRFUNC(json("{\"systemtap\": false}", "systemtap"))
BEGIN
/subr == DIF_SUBR_MAX + 1/
@@ -0,0 +1,179 @@
/*
* This file and its contents are supplied under the terms of the
* Common Development and Distribution License ("CDDL"), version 1.0.
* You may only use this file in accordance with the terms of version
* 1.0 of the CDDL.
*
* A full copy of the text of the CDDL should have accompanied this
* source. A copy of the CDDL is also available via the Internet at
* http://www.illumos.org/license/CDDL.
*/
/*
* Copyright 2012, Joyent, Inc. All rights reserved.
*/
/*
* General functional tests of JSON parser for json().
*/
#pragma D option quiet
#pragma D option strsize=1k
#define TST(name) \
printf("\ntst |%s|\n", name)
#define IN2(vala, valb) \
in = strjoin(vala, valb); \
printf("in |%s|\n", in)
#define IN(val) \
in = val; \
printf("in |%s|\n", in)
#define SEL(ss) \
out = json(in, ss); \
printf("sel |%s|\nout |%s|\n", ss, \
out != NULL ? out : "<NULL>")
BEGIN
{
TST("empty array");
IN("[]");
SEL("0");
TST("one-element array: integer");
IN("[1]");
SEL("0");
SEL("1");
SEL("100");
SEL("-1");
TST("one-element array: hex integer (not in spec, not supported)");
IN("[0x1000]");
SEL("0");
TST("one-element array: float");
IN("[1.5001]");
SEL("0");
TST("one-element array: float + exponent");
IN("[16.3e10]");
SEL("0");
TST("one-element array: integer + whitespace");
IN("[ \t 5\t]");
SEL("0");
TST("one-element array: integer + exponent + whitespace");
IN("[ \t \t 16E10 \t ]");
SEL("0");
TST("one-element array: string");
IN("[\"alpha\"]");
SEL("0");
TST("alternative first-element indexing");
IN("[1,5,10,15,20]");
SEL("[0]");
SEL("[3]");
SEL("[4]");
SEL("[5]");
TST("one-element array: object");
IN("[ { \"first\": true, \"second\": false }]");
SEL("0.first");
SEL("0.second");
SEL("0.third");
TST("many-element array: integers");
IN("[0,1,1,2,3,5,8,13,21,34,55,89,144,233,377]");
SEL("10"); /* F(10) = 55 */
SEL("14"); /* F(14) = 377 */
SEL("19");
TST("many-element array: multiple types");
IN2("[\"string\",32,true,{\"a\":9,\"b\":false},100.3e10,false,200.5,",
"{\"key\":\"val\"},null]");
SEL("0");
SEL("0.notobject");
SEL("1");
SEL("2");
SEL("3");
SEL("3.a");
SEL("3.b");
SEL("3.c");
SEL("4");
SEL("5");
SEL("6");
SEL("7");
SEL("7.key");
SEL("7.key.notobject");
SEL("7.nonexist");
SEL("8");
SEL("9");
TST("many-element array: multiple types + whitespace");
IN2("\n[\t\"string\" ,\t32 , true\t,\t {\"a\": 9,\t\"b\": false},\t\t",
"100.3e10, false, 200.5,{\"key\" \t:\n \"val\"},\t\t null ]\t\t");
SEL("0");
SEL("0.notobject");
SEL("1");
SEL("2");
SEL("3");
SEL("3.a");
SEL("3.b");
SEL("3.c");
SEL("4");
SEL("5");
SEL("6");
SEL("7");
SEL("7.key");
SEL("7.key.notobject");
SEL("7.nonexist");
SEL("8");
SEL("9");
TST("two-element array: various string escape codes");
IN2("[\"abcd \\\" \\\\ \\/ \\b \\f \\n \\r \\t \\u0000 \\uf00F \", ",
"\"final\"]");
SEL("0");
SEL("1");
TST("three-element array: broken escape code");
IN("[\"fine here\", \"dodgey \\u00AZ\", \"wont get here\"]");
SEL("0");
SEL("1");
SEL("2");
TST("nested objects");
IN2("{ \"top\": { \"mid\" : { \"legs\": \"feet\" }, \"number\": 9, ",
"\"array\":[0,1,{\"a\":true,\"bb\":[1,2,false,{\"x\":\"yz\"}]}]}}");
SEL("top");
SEL("fargo");
SEL("top.mid");
SEL("top.centre");
SEL("top.mid.legs");
SEL("top.mid.number");
SEL("top.mid.array");
SEL("top.number");
SEL("top.array");
SEL("top.array[0]");
SEL("top.array[1]");
SEL("top.array[2]");
SEL("top.array[2].a");
SEL("top.array[2].b");
SEL("top.array[2].bb");
SEL("top.array[2].bb[0]");
SEL("top.array[2].bb[1]");
SEL("top.array[2].bb[2]");
SEL("top.array[2].bb[3]");
SEL("top.array[2].bb[3].x");
SEL("top.array[2].bb[3].x.nofurther");
SEL("top.array[2].bb[4]");
SEL("top.array[3]");
exit(0);
}
ERROR
{
exit(1);
}
Oops, something went wrong.

0 comments on commit 8017f1f

Please sign in to comment.