summaryrefslogtreecommitdiff
path: root/fuzz
diff options
context:
space:
mode:
authorTizenOpenSource <tizenopensrc@samsung.com>2024-01-22 15:17:04 +0900
committerTizenOpenSource <tizenopensrc@samsung.com>2024-01-22 15:17:04 +0900
commitd6ea7e7c4172902086eab521ac7e74fab2009efd (patch)
treeb52a4d6e16b14445a5b6c7b7d6b893813fdaa490 /fuzz
parentd97bcaac29892fdfedf726d9127af64b98390d1c (diff)
downloadre2c-upstream.tar.gz
re2c-upstream.tar.bz2
re2c-upstream.zip
Imported Upstream version 3.1upstream/3.1upstream
Diffstat (limited to 'fuzz')
-rwxr-xr-xfuzz/tdfa_stadfa2/__mk.sh4
-rw-r--r--fuzz/tdfa_stadfa2/check.hs132
2 files changed, 0 insertions, 136 deletions
diff --git a/fuzz/tdfa_stadfa2/__mk.sh b/fuzz/tdfa_stadfa2/__mk.sh
deleted file mode 100755
index 1025a551..00000000
--- a/fuzz/tdfa_stadfa2/__mk.sh
+++ /dev/null
@@ -1,4 +0,0 @@
-
-[ -x ../re2c ] || { echo "*** no re2c found ***"; exit 1; }
-
-ghc check.hs -Wall -fforce-recomp -O2
diff --git a/fuzz/tdfa_stadfa2/check.hs b/fuzz/tdfa_stadfa2/check.hs
deleted file mode 100644
index d3db4788..00000000
--- a/fuzz/tdfa_stadfa2/check.hs
+++ /dev/null
@@ -1,132 +0,0 @@
-
-import qualified Test.QuickCheck as Q
-import qualified Test.QuickCheck.Monadic as QM
-import qualified System.Process as SP
-import qualified System.Exit as SE
-import qualified Data.ByteString.Char8 as BS
-import Data.Char (chr)
-import Control.Monad (when)
-
-
-data E = A | B | C
- | Empty
- | NA | NB | NC
- | Tag String
- | HTag String
- | Alt E E
- | Cat E E
- | Star E
- | Plus E
- | Mayb E
- | FromTo Int Int E
- | From Int E
-
-
-instance Show E where
- show x = case x of
- A -> "[a]"
- B -> "[b]"
- C -> "[c]"
- Empty -> "\"\""
- NA -> "[^a]"
- NB -> "[^b]"
- NC -> "[^c]"
- Tag s -> "@t_" ++ s
- HTag s -> "#t_" ++ s
- Alt l r -> "(" ++ show l ++ "|" ++ show r ++ ")"
- Cat l r -> "(" ++ show l ++ show r ++ ")"
- Star e -> "(" ++ show e ++ ")*"
- Plus e -> "(" ++ show e ++ ")+"
- Mayb e -> "(" ++ show e ++ ")?"
- FromTo n m e -> "(" ++ show e ++ "){" ++ show n ++ "," ++ show m ++ "}"
- From n e -> "(" ++ show e ++ "){" ++ show n ++ ",}"
-
-instance Q.Arbitrary E where
- arbitrary = do
- d <- Q.choose (2, 5) :: Q.Gen Int
- arbitrary_d d
-
-
-arbitrary_d :: (Enum a, Eq a, Num a) => a -> Q.Gen E
-arbitrary_d 0 = do
- tag <- take 5 <$> Q.infiniteListOf (Q.choose (97, 122) :: Q.Gen Int)
- Q.frequency
- [ (1, pure Empty)
- , (1, pure A)
- , (1, pure B)
- , (1, pure C)
- , (1, pure NA)
- , (1, pure NB)
- , (1, pure NC)
- , (2, pure $ Tag $ map chr tag)
- , (2, pure $ HTag $ map chr tag)
- ]
-arbitrary_d d = do
- n <- Q.choose (0, 3) :: Q.Gen Int
- m <- Q.choose (if n < 2 then n + 1 else n, 3) :: Q.Gen Int
- Q.frequency
- [ (1, pure Empty)
- , (1, pure A)
- , (1, pure B)
- , (1, pure C)
- , (1, pure NA)
- , (1, pure NB)
- , (1, pure NC)
- , (30, Alt <$> arbitrary_d d' <*> arbitrary_d d')
- , (30, Cat <$> arbitrary_d d' <*> arbitrary_d d')
- , (10, Star <$> arbitrary_d d')
- , (10, Plus <$> arbitrary_d d')
- , (10, Mayb <$> arbitrary_d d')
- , (10, FromTo n m <$> arbitrary_d d')
- , (10, From n <$> arbitrary_d d')
- ]
- where d' = pred d
-
-
-prop_test_re2c :: E -> E -> Q.Property
-prop_test_re2c r1 r2 = QM.monadicIO $ do
- let re_file = unlines [ "/*!re2c"
- , show r1 ++ " {}"
- , show r2 ++ " {}"
- , "\"\" {}"
- , "*/"
- ]
- re2c = "../re2c"
- re2c_flags = " -Werror-undefined-control-flow -ST " -- ++ "--posix-captures "
- cxx = "gcc"
- cxx_flags = " -Werror=incompatible-pointer-types "
-
- QM.run $ do
- BS.writeFile "a.re" $ BS.pack re_file
-
- s0 <- QM.run $ do
- SP.system $ concat
- [ "ulimit -t 10 && "
- , re2c ++ re2c_flags ++ " --stadfa a.re -o a.c 2>>re2c_last_warning "
- , "&& " ++ cxx ++ cxx_flags ++ " a.c -o a && ./a "
- , "&& cp a.c b.c"
- ]
-
- s1 <- QM.run $ do
- SP.system $ concat
- [ "ulimit -t 10 && "
- , re2c ++ re2c_flags ++ " a.re -o a.c 2>>re2c_last_warning "
- , "&& " ++ cxx ++ cxx_flags ++ " a.c -o a && ./a "
- ]
- QM.assert $ s0 `elem` [SE.ExitSuccess, SE.ExitFailure 137]
- QM.assert $ s1 `elem` [SE.ExitSuccess, SE.ExitFailure 137]
-
- when (s0 == SE.ExitSuccess && s1 == SE.ExitSuccess) $ do
- s01 <- QM.run $ do
- SP.system "s='#define YYKEYTYPE'; a=`grep \"$s\" a.c`; b=`grep \"$s\" b.c`; test \"$a\" = \"$b\""
- when (s01 == SE.ExitSuccess) $ do
- s2 <- QM.run $ do
- SP.system $ concat
- [ "ulimit -t 10 && "
- , cxx ++ cxx_flags ++ " b.c -o b && ./b "
- ]
- QM.assert $ s2 == SE.ExitSuccess
-
-
-main :: IO ()
-main = Q.quickCheckWith Q.stdArgs { Q.maxSuccess = 1000000 } prop_test_re2c