1 /*
2  * Copyright (C) 2012 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */
16 
17 #ifndef CTSAUDIO_SIMPLESCRIPTEXEC_H
18 #define CTSAUDIO_SIMPLESCRIPTEXEC_H
19 
20 #include <sys/types.h>
21 #include <regex.h>
22 
23 #include <utils/String8.h>
24 
25 /**
26  * Utility class for executing simple scripts
27  * which prints ___CTS_AUDIO_PASS___ string in output
28  */
29 class SimpleScriptExec {
30 public:
31     static const char* PYTHON_PATH;
32 
33     static bool checkPythonEnv();
34     /**
35      * run given script
36      * @param script full path of the script
37      * @param param arguments to pass
38      * @param result
39      */
40     static bool runScript(const android::String8& script, const android::String8& param,
41             android::String8& result);
42 
43     /**
44      * check if the given str include magic words for pass.
45      * @param str
46      * @param reMatch pattern to match in re besides the pass string
47      * @param nmatch number of substring pattern match elements. It should be in POSIX
48      *        extended RE syntax, no \d nor [:digit:]
49      * @param pmatch pattern match elements
50      * @return true if passed
51      */
52     static bool checkIfPassed(const android::String8& str, const android::String8& reMatch,
53             int nmatch = 0, regmatch_t pmatch[] = NULL);
54 };
55 
56 
57 #endif // CTSAUDIO_SIMPLESCRIPTEXEC_H
58