diff options
-rw-r--r-- | tapset/ChangeLog | 4 | ||||
-rw-r--r-- | tapset/string.stp | 32 | ||||
-rw-r--r-- | testsuite/ChangeLog | 6 | ||||
-rw-r--r-- | testsuite/systemtap.string/strtol.exp | 15 | ||||
-rw-r--r-- | testsuite/systemtap.string/strtol.stp | 29 | ||||
-rw-r--r-- | testsuite/systemtap.string/tokenize.exp | 26 | ||||
-rw-r--r-- | testsuite/systemtap.string/tokenize.stp | 46 |
7 files changed, 158 insertions, 0 deletions
diff --git a/tapset/ChangeLog b/tapset/ChangeLog index a7408fe7..33eef001 100644 --- a/tapset/ChangeLog +++ b/tapset/ChangeLog @@ -1,3 +1,7 @@ +2007-01-23 Mike Mason <mmlnx@us.ibm.com> + + * string.stp: Added tokenize() and strtol() functions. + 2007-01-17 Martin Hunt <hunt@redhat.com> * syscalls.stp: Add syscall.creat. diff --git a/tapset/string.stp b/tapset/string.stp index 77925d0d..15791134 100644 --- a/tapset/string.stp +++ b/tapset/string.stp @@ -58,5 +58,37 @@ function text_strn:string(input:string, len:long, quoted:long) _stp_text_str(THIS->__retvalue, THIS->input, THIS->len, THIS->quoted, 0); %} +/* + * tokenize - Given a string and a token delimiter, + * return the next token in the string + * input String to tokenize. If NULL, returns the next token in the + * string passed in the previous call to tokenize(). + * delim Token delimiter. Note this is a string, but only the first + * character is used as the delimiter. + */ +function tokenize:string(input:string, delim:string) +%{ /* pure */ + static char str[MAXSTRINGLEN]; + static char *str_start; + char *token = NULL; + + if (THIS->input[0]) { + strncpy(str, THIS->input, MAXSTRINGLEN); + str_start = &str[0]; + } + token = strsep(&str_start, THIS->delim); + if (token) + strncpy (THIS->__retvalue, token, MAXSTRINGLEN); +%} + +/* + * strtol - Convert a string to a long + * str String to convert + * base The base to use + */ +function strtol:long(str:string, base:long) +%{ /* pure */ + THIS->__retvalue = simple_strtol(THIS->str, NULL, THIS->base); +%} /** @} */ diff --git a/testsuite/ChangeLog b/testsuite/ChangeLog index e34d66f2..82749ee7 100644 --- a/testsuite/ChangeLog +++ b/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2007-01-23 Mike Mason <mmlnx@us.ibm.com> + + * systemtap.string/tokenize.exp, systemtap.string/tokenize.stp, + systemtap.string/strtol.exp, systemtap.string/strtol.stp: + Tests for new tokenize and strtol functions. + 2007-01-22 Josh Stone <joshua.i.stone@intel.com> * systemtap.base/deref.stp: Rewrite test, and now also check the ability diff --git a/testsuite/systemtap.string/strtol.exp b/testsuite/systemtap.string/strtol.exp new file mode 100644 index 00000000..12d63f0d --- /dev/null +++ b/testsuite/systemtap.string/strtol.exp @@ -0,0 +1,15 @@ +set test "strtol" +set ::result_string {1 +-1 +123456789 +-123456789 +0 +1 +0 +0 +1000 +4096 +512 +8 +0} +stap_run2 $srcdir/$subdir/$test.stp diff --git a/testsuite/systemtap.string/strtol.stp b/testsuite/systemtap.string/strtol.stp new file mode 100644 index 00000000..dcd1fe71 --- /dev/null +++ b/testsuite/systemtap.string/strtol.stp @@ -0,0 +1,29 @@ +probe begin +{ + teststr1 = "1" + teststr2 = "-1" + teststr3 = "123456789" + teststr4 = "-123456789" + teststr5 = "abcdef" + teststr6 = "123456789abcdef" + teststr7 = " 1 2 3 4" + teststr8 = "" + teststr9 = "1000" + teststr6 = "1a2b3c4d5e6f7g8h9" + + printf("%d\n", strtol(teststr1, 10)) + printf("%d\n", strtol(teststr2, 10)) + printf("%d\n", strtol(teststr3, 10)) + printf("%d\n", strtol(teststr4, 10)) + printf("%d\n", strtol(teststr5, 10)) + printf("%d\n", strtol(teststr6, 10)) + printf("%d\n", strtol(teststr7, 10)) + printf("%d\n", strtol(teststr8, 10)) + printf("%d\n", strtol(teststr9, 10)) + printf("%d\n", strtol(teststr9, 16)) + printf("%d\n", strtol(teststr9, 8)) + printf("%d\n", strtol(teststr9, 2)) + printf("%d\n", strtol(teststr10, 2)) + + exit() +} diff --git a/testsuite/systemtap.string/tokenize.exp b/testsuite/systemtap.string/tokenize.exp new file mode 100644 index 00000000..697b7c7e --- /dev/null +++ b/testsuite/systemtap.string/tokenize.exp @@ -0,0 +1,26 @@ +set test "tokenize" +set ::result_string {one +two +three +four +five +six +seven +eight +nine +ten +one|two|three|four|five|six|seven|eight|nine|ten +a +b +c +d +e +f +g +1 +2 +3 + +4 +this is a string with no delimiters} +stap_run2 $srcdir/$subdir/$test.stp diff --git a/testsuite/systemtap.string/tokenize.stp b/testsuite/systemtap.string/tokenize.stp new file mode 100644 index 00000000..10703d90 --- /dev/null +++ b/testsuite/systemtap.string/tokenize.stp @@ -0,0 +1,46 @@ +probe begin +{ + teststr1 = "one|two|three|four|five|six|seven|eight|nine|ten" + teststr2 = "a,b,c,d,e,f,g" + teststr3 = "1,,2,3, ,4" + teststr4 = "" + teststr5 = "this is a string with no delimiters" + + tok = tokenize(teststr1, "|") + while (tok != "") { + printf("%s\n", tok) + tok = tokenize("", "|") + } + + tok = tokenize(teststr1, ",") + while (tok != "") { + printf("%s\n", tok) + tok = tokenize("", "|") + } + + tok = tokenize(teststr2, ",") + while (tok != "") { + printf("%s\n", tok) + tok = tokenize("", ",") + } + + tok = tokenize(teststr3, ",") + while (tok != "") { + printf("%s\n", tok) + tok = tokenize("", ",") + } + + tok = tokenize(teststr4, ",") + while (tok != "") { + printf("%s\n", tok) + tok = tokenize("", ",") + } + + tok = tokenize(teststr5, ",") + while (tok != "") { + printf("%s\n", tok) + tok = tokenize("", ",") + } + + exit() +} |