1{-# LANGUAGE DeriveDataTypeable #-}
2{-# LANGUAGE OverloadedStrings #-}
3{-# OPTIONS_GHC -fno-warn-missing-fields #-}
4{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
5{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
6{-# OPTIONS_GHC -fno-warn-unused-imports #-}
7{-# OPTIONS_GHC -fno-warn-unused-matches #-}
8
9-----------------------------------------------------------------
10-- Autogenerated by Thrift
11--                                                             --
12-- DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
13--  @generated
14-----------------------------------------------------------------
15
16module TestService_Fuzzer (main) where
17import qualified Module_Types
18import qualified TestService_Client as Client
19
20import Prelude ( Bool(..), Enum, Float, IO, Double, String, Maybe(..),
21                 Eq, Show, Ord,
22                 concat, error, fromIntegral, fromEnum, length, map,
23                 maybe, not, null, otherwise, return, show, toEnum,
24                 enumFromTo, Bounded, minBound, maxBound, seq, succ,
25                 pred, enumFrom, enumFromThen, enumFromThenTo,
26                 (.), (&&), (||), (==), (++), ($), (-), (>>=), (>>))
27
28import qualified Control.Applicative as Applicative (ZipList(..))
29import Control.Applicative ( (<*>) )
30import qualified Control.DeepSeq as DeepSeq
31import qualified Control.Exception as Exception
32import qualified Control.Monad as Monad ( liftM, ap, when )
33import qualified Data.ByteString.Lazy as BS
34import Data.Functor ( (<$>) )
35import qualified Data.Hashable as Hashable
36import qualified Data.Int as Int
37import Data.List
38import qualified Data.Maybe as Maybe (catMaybes)
39import qualified Data.Text.Lazy.Encoding as Encoding ( decodeUtf8, encodeUtf8 )
40import qualified Data.Text.Lazy as LT
41import qualified Data.Typeable as Typeable ( Typeable )
42import qualified Data.HashMap.Strict as Map
43import qualified Data.HashSet as Set
44import qualified Data.Vector as Vector
45import qualified Test.QuickCheck.Arbitrary as Arbitrary ( Arbitrary(..) )
46import qualified Test.QuickCheck as QuickCheck ( elements )
47
48import qualified Thrift
49import qualified Thrift.Types as Types
50import qualified Thrift.Serializable as Serializable
51import qualified Thrift.Arbitraries as Arbitraries
52
53import Prelude ((>>), print)
54import qualified Prelude as P
55import Control.Monad (forM)
56import qualified Data.List as L
57import Data.Maybe (fromJust)
58import qualified Data.Map as Map
59import GHC.Int (Int64, Int32)
60import Data.ByteString.Lazy (ByteString)
61import System.Environment (getArgs)
62import Test.QuickCheck (arbitrary)
63import Test.QuickCheck.Gen (Gen(..))
64import Thrift.FuzzerSupport
65
66
67handleOptions :: ([Options -> Options], [String], [String]) -> Options
68handleOptions (transformers, (serviceName:[]), []) | serviceName `P.elem` serviceNames
69    = (P.foldl (P.flip ($)) defaultOptions transformers) { opt_service = serviceName }
70handleOptions (_, (serviceName:[]), []) | P.otherwise
71    = P.error $ usage ++ "\nUnknown serviceName " ++ serviceName ++ ", should be one of " ++ (P.show serviceNames)
72handleOptions (_, [], _) = P.error $ usage ++ "\nMissing mandatory serviceName to fuzz."
73handleOptions (_, _a, []) = P.error $ usage ++ "\nToo many serviceNames, pick one."
74handleOptions (_, _, e) = P.error $ usage ++ (P.show e)
75
76main :: IO ()
77main = do
78    args <- getArgs
79    let config = handleOptions (getOptions args)
80    fuzz config
81
82selectFuzzer :: Options -> (Options -> IO ())
83selectFuzzer (Options _host _port service _timeout _framed _verbose)
84    = fromJust $ P.lookup service fuzzerFunctions
85
86fuzz :: Options -> IO ()
87fuzz config = (selectFuzzer config) config
88
89-- Dynamic content
90
91-- Configuration via command-line parsing
92
93serviceNames :: [String]
94serviceNames = ["init"]
95
96fuzzerFunctions :: [(String, (Options -> IO ()))]
97fuzzerFunctions = [("init", init_fuzzer)]
98
99-- Random data generation
100inf_Int_Int64 :: IO [Int.Int64]
101inf_Int_Int64 = infexamples (Arbitrary.arbitrary :: Gen Int.Int64)
102
103-- Fuzzers and exception handlers
104init_fuzzer :: Options -> IO ()
105init_fuzzer opts = do
106  a1 <- Applicative.ZipList <$> inf_Int_Int64
107  a2 <- Applicative.ZipList <$> inf_Int_Int64
108  a3 <- Applicative.ZipList <$> inf_Int_Int64
109  a4 <- Applicative.ZipList <$> inf_Int_Int64
110  a5 <- Applicative.ZipList <$> inf_Int_Int64
111  a6 <- Applicative.ZipList <$> inf_Int_Int64
112  a7 <- Applicative.ZipList <$> inf_Int_Int64
113  a8 <- Applicative.ZipList <$> inf_Int_Int64
114  a9 <- Applicative.ZipList <$> inf_Int_Int64
115  a10 <- Applicative.ZipList <$> inf_Int_Int64
116  a11 <- Applicative.ZipList <$> inf_Int_Int64
117  a12 <- Applicative.ZipList <$> inf_Int_Int64
118  a13 <- Applicative.ZipList <$> inf_Int_Int64
119  a14 <- Applicative.ZipList <$> inf_Int_Int64
120  a15 <- Applicative.ZipList <$> inf_Int_Int64
121  a16 <- Applicative.ZipList <$> inf_Int_Int64
122  _ <- P.sequence . Applicative.getZipList $ init_fuzzFunc <$> a1 <*> a2 <*> a3 <*> a4 <*> a5 <*> a6 <*> a7 <*> a8 <*> a9 <*> a10 <*> a11 <*> a12 <*> a13 <*> a14 <*> a15 <*> a16
123  return ()
124  where
125  init_fuzzFunc a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 = let param = (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16) in
126    if opt_framed opts
127    then withThriftDo opts (withFramedTransport opts) (init_fuzzOnce param) (init_exceptionHandler param)
128    else withThriftDo opts (withHandle opts) (init_fuzzOnce param) (init_exceptionHandler param)
129
130init_exceptionHandler :: (Show a1, Show a2, Show a3, Show a4, Show a5, Show a6, Show a7, Show a8, Show a9, Show a10, Show a11, Show a12, Show a13, Show a14, Show a15, Show a16) => (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16) -> IO ()
131init_exceptionHandler (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16) = do
132  P.putStrLn $ "Got exception on data:"
133  P.putStrLn $ "(" ++ show a1 ++ show a2 ++ show a3 ++ show a4 ++ show a5 ++ show a6 ++ show a7 ++ show a8 ++ show a9 ++ show a10 ++ show a11 ++ show a12 ++ show a13 ++ show a14 ++ show a15 ++ show a16 ++ ")"
134init_fuzzOnce (a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16) client = Client.init client a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 >> return ()
135
136