瀏覽代碼

Add tests for config parsing

Three parts to this change:
- Add support for custom config file parameter to ch
- Added support in RL to pass in a custom config file. If this is
  passed in, it overrides any of the other flags and is passed to
  the javascript host process
- Added a few test cases to validate config parsing
Hitesh Kanwathirtha 8 年之前
父節點
當前提交
0e49a1ffc1

+ 9 - 0
bin/ChakraCore/TestHooks.cpp

@@ -3,6 +3,7 @@
 // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
 //-------------------------------------------------------------------------------------------------------
 #include "Runtime.h"
+#include "Core/ConfigParser.h"
 #include "TestHooks.h"
 
 #ifdef ENABLE_TEST_HOOKS
@@ -18,6 +19,13 @@ HRESULT __stdcall SetConfigFlags(__in int argc, __in_ecount(argc) LPWSTR argv[],
     return S_OK;
 }
 
+HRESULT __stdcall SetConfigFile(__in LPWSTR strConfigFile)
+{
+    CmdLineArgsParser parser;
+    ConfigParser::ParseCustomConfigFile(parser, strConfigFile);
+    return S_OK;
+}
+
 HRESULT __stdcall PrintConfigFlagsUsageString()
 {
     Js::ConfigFlagsTable::PrintUsageString();
@@ -141,6 +149,7 @@ HRESULT OnChakraCoreLoaded(OnChakraCoreLoadedPtr pfChakraCoreLoaded)
     TestHooks testHooks =
     {
         SetConfigFlags,
+        SetConfigFile,
         PrintConfigFlagsUsageString,
         SetAssertToConsoleFlag,
         SetEnableCheckMemoryLeakOutput,

+ 2 - 0
bin/ChakraCore/TestHooks.h

@@ -17,12 +17,14 @@ interface ICustomConfigFlags;
 struct TestHooks
 {
     typedef HRESULT(TESTHOOK_CALL *SetConfigFlagsPtr)(int argc, LPWSTR argv[], ICustomConfigFlags* customConfigFlags);
+    typedef HRESULT(TESTHOOK_CALL *SetConfigFilePtr)(LPWSTR strConfigFile);
     typedef HRESULT(TESTHOOK_CALL *PrintConfigFlagsUsageStringPtr)(void);
     typedef HRESULT(TESTHOOK_CALL *SetAssertToConsoleFlagPtr)(bool flag);
     typedef HRESULT(TESTHOOK_CALL *SetEnableCheckMemoryLeakOutputPtr)(bool flag);
     typedef void(TESTHOOK_CALL * NotifyUnhandledExceptionPtr)(PEXCEPTION_POINTERS exceptionInfo);
 
     SetConfigFlagsPtr pfSetConfigFlags;
+    SetConfigFilePtr  pfSetConfigFile;
     PrintConfigFlagsUsageStringPtr pfPrintConfigFlagsUsageString;
     SetAssertToConsoleFlagPtr pfSetAssertToConsoleFlag;
     SetEnableCheckMemoryLeakOutputPtr pfSetEnableCheckMemoryLeakOutput;

+ 1 - 0
bin/ch/ChakraRtInterface.h

@@ -267,6 +267,7 @@ public:
 
     static HRESULT SetAssertToConsoleFlag(bool flag) { return CHECKED_CALL(SetAssertToConsoleFlag, flag); }
     static HRESULT SetConfigFlags(__in int argc, __in_ecount(argc) LPWSTR argv[], ICustomConfigFlags* customConfigFlags) { return CHECKED_CALL(SetConfigFlags, argc, argv, customConfigFlags); }
+    static HRESULT SetConfigFile(__in LPWSTR strConfigFileName) { return CHECKED_CALL(SetConfigFile, strConfigFileName); }
     static HRESULT GetFileNameFlag(BSTR * filename) { return CHECKED_CALL(GetFilenameFlag, filename); }
     static HRESULT PrintConfigFlagsUsageString() { m_usageStringPrinted = true;  return CHECKED_CALL(PrintConfigFlagsUsageString); }
 

+ 1 - 0
bin/ch/HostConfigFlagsList.h

@@ -16,5 +16,6 @@ FLAG(bool, MuteHostErrorMsg,                "Mute host error output, e.g. module
 FLAG(bool, TraceHostCallback,               "Output traces for host callbacks", false)
 FLAG(bool, Test262,                         "load Test262 harness", false)
 FLAG(bool, TrackRejectedPromises,           "Enable tracking of unhandled promise rejections", false)
+FLAG(BSTR, CustomConfigFile,                "Custom config file to be used to pass in additional flags to Chakra", NULL)
 #undef FLAG
 #endif

+ 5 - 0
bin/ch/ch.cpp

@@ -1109,6 +1109,11 @@ int _cdecl wmain(int argc, __in_ecount(argc) LPWSTR argv[])
 
     if (success)
     {
+        if (HostConfigFlags::flags.CustomConfigFile != NULL) 
+        {
+            ChakraRTInterface::SetConfigFile(HostConfigFlags::flags.CustomConfigFile);
+        }
+
 #ifdef _WIN32
 #if ENABLE_NATIVE_CODEGEN
         if (HostConfigFlags::flags.OOPJIT)

+ 1 - 0
bin/rl/rl.cpp

@@ -275,6 +275,7 @@ const char * const TestInfoKindName[] =
    "timeout",
    "sourcepath",
    "eol-normalization",
+   "custom-config-file",
    NULL
 };
 static_assert((sizeof(TestInfoKindName) / sizeof(TestInfoKindName[0])) - 1 == TestInfoKind::_TIK_COUNT, "Fix the buffer size");

+ 1 - 0
bin/rl/rl.h

@@ -205,6 +205,7 @@ enum TestInfoKind
    TIK_TIMEOUT,
    TIK_SOURCE_PATH,
    TIK_EOL_NORMALIZATION,
+   TIK_CUSTOM_CONFIG_FILE,
    _TIK_COUNT
 };
 

+ 13 - 1
bin/rl/rlrun.cpp

@@ -524,7 +524,19 @@ int
         {
             cmd = pTestVariant->testInfo.data[TIK_COMMAND];
         }
-        sprintf_s(cmdbuf, "%s %s %s %s %s >%s 2>&1", cmd, optFlags, tempExtraCCFlags, ccFlags, testCmd, full);
+
+        //
+        // If the test is a JS test and we've passed in a custom config file, 
+        // ignore all of the other flags and just pass the config file in
+        //
+        if (kind == TK_JSCRIPT && pTestVariant->testInfo.data[TIK_CUSTOM_CONFIG_FILE] != nullptr)
+        {
+            sprintf_s(cmdbuf, "%s -CustomConfigFile:%s %s >%s 2>&1", cmd, pTestVariant->testInfo.data[TIK_CUSTOM_CONFIG_FILE], testCmd, full);
+        }
+        else
+        {
+            sprintf_s(cmdbuf, "%s %s %s %s %s >%s 2>&1", cmd, optFlags, tempExtraCCFlags, ccFlags, testCmd, full);
+        }
 
         Message("Running '%s'", cmdbuf);
 

+ 1 - 0
jenkins/check_copyright.sh

@@ -37,6 +37,7 @@ git diff --name-only `git merge-base origin/$ghprbTargetBranch HEAD` HEAD |
     grep -v -E '\.cmake$' |
     grep -v -E '\.json$' |
     grep -v -E '\.man$' |
+    grep -v -E '\.testconfig$' |
     grep -v -E 'lib/wabt/.*' |
     grep -v -E 'test/WasmSpec.*$' |
     grep -v -E 'test/UnitTestFramework/yargs.js$' |

+ 16 - 6
lib/Common/Core/ConfigParser.cpp

@@ -327,13 +327,23 @@ void ConfigParser::ParseRegistryKey(HKEY hk, CmdLineArgsParser &parser)
 #endif // _WIN32
 }
 
-
-void ConfigParser::ParseConfig(HANDLE hmod, CmdLineArgsParser &parser)
+void ConfigParser::ParseConfig(HANDLE hmod, CmdLineArgsParser &parser, const char16* strCustomConfigFile)
 {
 #if defined(ENABLE_DEBUG_CONFIG_OPTIONS) && CONFIG_PARSE_CONFIG_FILE
-    Assert(!_hasReadConfig);
+    Assert(!_hasReadConfig || strCustomConfigFile != nullptr);
     _hasReadConfig = true;
 
+    const char16* configFileName = strCustomConfigFile;
+    const char16* configFileExt = _u(""); /* in the custom config case,
+                                             ext is expected to be passed
+                                             in as part of the filename */
+
+    if (configFileName == nullptr)
+    {
+        configFileName = _configFileName;
+        configFileExt = _u(".config");
+    }
+
     int err = 0;
     char16 modulename[_MAX_PATH];
     char16 filename[_MAX_PATH];
@@ -343,7 +353,7 @@ void ConfigParser::ParseConfig(HANDLE hmod, CmdLineArgsParser &parser)
     char16 dir[_MAX_DIR];
 
     _wsplitpath_s(modulename, drive, _MAX_DRIVE, dir, _MAX_DIR, nullptr, 0, nullptr, 0);
-    _wmakepath_s(filename, drive, dir, _configFileName, _u(".config"));
+    _wmakepath_s(filename, drive, dir, configFileName, configFileExt);
 
     FILE* configFile;
 #ifdef _WIN32
@@ -351,7 +361,7 @@ void ConfigParser::ParseConfig(HANDLE hmod, CmdLineArgsParser &parser)
     {
         WCHAR configFileFullName[MAX_PATH];
 
-        StringCchPrintf(configFileFullName, MAX_PATH, _u("%s.config"), _configFileName);
+        StringCchPrintf(configFileFullName, MAX_PATH, _u("%s%s"), configFileName, configFileExt);
 
         // try the one in the current working directory (Desktop)
         if (_wfullpath(filename, configFileFullName, _MAX_PATH) == nullptr)
@@ -381,7 +391,7 @@ void ConfigParser::ParseConfig(HANDLE hmod, CmdLineArgsParser &parser)
         
         WCHAR configFileFullName[MAX_PATH];
 
-        StringCchPrintf(configFileFullName, MAX_PATH, _u("%s/%s.config"), homeDir, _configFileName);
+        StringCchPrintf(configFileFullName, MAX_PATH, _u("%s/%s%s"), homeDir, configFileName, configFileExt);
         if (_wfopen_s(&configFile, configFileFullName, _u("r")) != 0 || configFile == nullptr)
         {
             return;

+ 8 - 1
lib/Common/Core/ConfigParser.h

@@ -51,7 +51,14 @@ public:
 
     static void ParseOnModuleLoad(CmdLineArgsParser& parser, HANDLE hMod);
 
-    void ParseConfig(HANDLE hmod, CmdLineArgsParser &parser);
+#ifdef ENABLE_TEST_HOOKS
+    static void ParseCustomConfigFile(CmdLineArgsParser& parser, const char16* strConfigFile)
+    {
+        s_moduleConfigParser.ParseConfig(NULL /* hMod */, parser, strConfigFile);
+    }
+#endif
+
+    void ParseConfig(HANDLE hmod, CmdLineArgsParser &parser, const char16* strCustomConfigFile = nullptr);
     void ParseRegistry(CmdLineArgsParser &parser);
     void ProcessConfiguration(HANDLE mod);
     HRESULT SetOutputFile(const WCHAR* outputFile, const WCHAR* openMode);

+ 1 - 0
test/ConfigParsing/dummy.baseline

@@ -0,0 +1 @@
+FLAG NoNative = 1

+ 6 - 0
test/ConfigParsing/dummy.js

@@ -0,0 +1,6 @@
+//-------------------------------------------------------------------------------------------------------
+// Copyright (C) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
+//-------------------------------------------------------------------------------------------------------
+
+(function() {})();

+ 2 - 0
test/ConfigParsing/interspersednewline.testconfig

@@ -0,0 +1,2 @@
+-Verbose
+-NoNative

+ 2 - 0
test/ConfigParsing/interspersednewline_leadingwhitespace.testconfig

@@ -0,0 +1,2 @@
+ -Verbose
+-NoNative

+ 2 - 0
test/ConfigParsing/interspersednewline_whitespace.testconfig

@@ -0,0 +1,2 @@
+-Verbose
+ -NoNative

+ 1 - 0
test/ConfigParsing/leadingwhitespace.testconfig

@@ -0,0 +1 @@
+ -Verbose -NoNative

+ 39 - 0
test/ConfigParsing/rlexe.xml

@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="utf-8"?>
+<regress-exe>
+  <test>
+    <default>
+      <files>dummy.js</files>
+      <baseline>dummy.baseline</baseline>
+      <custom-config-file>standard.testconfig</custom-config-file>
+    </default>
+  </test>
+  <test>
+    <default>
+      <files>dummy.js</files>
+      <baseline>dummy.baseline</baseline>
+      <custom-config-file>leadingwhitespace.testconfig</custom-config-file>
+    </default>
+  </test>
+  <test>
+    <default>
+      <files>dummy.js</files>
+      <baseline>dummy.baseline</baseline>
+      <custom-config-file>interspersednewline.testconfig</custom-config-file>
+    </default>
+  </test>
+  <test>
+    <default>
+      <files>dummy.js</files>
+      <baseline>dummy.baseline</baseline>
+      <custom-config-file>interspersednewline_whitespace.testconfig</custom-config-file>
+    </default>
+  </test>
+  <test>
+    <default>
+      <files>dummy.js</files>
+      <baseline>dummy.baseline</baseline>
+      <custom-config-file>interspersednewline_leadingwhitespace.testconfig</custom-config-file>
+    </default>
+  </test>
+
+</regress-exe>

+ 1 - 0
test/ConfigParsing/standard.testconfig

@@ -0,0 +1 @@
+-Verbose -NoNative

+ 6 - 0
test/rlexedirs.xml

@@ -20,6 +20,12 @@
     <files>Basics</files>
   </default>
 </dir>
+<dir>
+  <default>
+    <files>ConfigParsing</files>
+    <tags>exclude_jshost,exclude_xplat</tags>
+  </default>
+</dir>
 <dir>
   <default>
     <files>es5</files>