Switch to individual test registration.

This commit is contained in:
Ryan Prichard 2015-10-25 01:45:24 -05:00
parent 7bdbce5e2c
commit a17fac4e5a
6 changed files with 24 additions and 58 deletions

View File

@ -1,10 +1,10 @@
#include <TestCommon.h>
REGISTER(Test_CreateProcess_ModeCombos, always);
static void Test_CreateProcess_ModeCombos() {
// It is often unclear how (or whether) various combinations of
// CreateProcess parameters work when combined. Try to test the ambiguous
// combinations.
printTestName(__FUNCTION__);
DWORD errCode = 0;
@ -32,9 +32,9 @@ static void Test_CreateProcess_ModeCombos() {
}
}
REGISTER(Test_CreateProcess_STARTUPINFOEX, isAtLeastVista);
static void Test_CreateProcess_STARTUPINFOEX() {
// STARTUPINFOEX tests.
printTestName(__FUNCTION__);
Worker p;
DWORD errCode = 0;
@ -178,8 +178,8 @@ static void Test_CreateProcess_STARTUPINFOEX() {
}
}
REGISTER(Test_CreateNoWindow_HiddenVsNothing, always);
static void Test_CreateNoWindow_HiddenVsNothing() {
printTestName(__FUNCTION__);
Worker p;
auto c = p.child({ false, CREATE_NO_WINDOW });
@ -195,6 +195,7 @@ static void Test_CreateNoWindow_HiddenVsNothing() {
}
}
REGISTER(Test_CreateProcess_DefaultInherit, always);
static void Test_CreateProcess_DefaultInherit() {
// If CreateProcess is called with these parameters:
// - bInheritHandles=FALSE
@ -205,8 +206,6 @@ static void Test_CreateProcess_DefaultInherit() {
// There are variations between OS releases, especially with regards to
// how console handles work.
printTestName(__FUNCTION__);
{
// Base case: a non-inheritable pipe is still inherited.
Worker p;
@ -377,15 +376,3 @@ static void Test_CreateProcess_DefaultInherit() {
// XXX: The word "even" here sticks out. Verify that the standard handle
// fields in STARTUPINFO are ignored when STARTF_USESTDHANDLES is not
// specified.
REGISTER(run_CreateProcess, always);
void run_CreateProcess() {
Test_CreateProcess_ModeCombos();
if (isAtLeastVista()) {
Test_CreateProcess_STARTUPINFOEX();
}
Test_CreateNoWindow_HiddenVsNothing();
Test_CreateProcess_DefaultInherit();
}

View File

@ -1,11 +1,11 @@
#include <TestCommon.h>
REGISTER(Test_IntrinsicInheritFlags, always);
static void Test_IntrinsicInheritFlags() {
// Console handles have an inherit flag, just as kernel handles do.
//
// In Windows 7, there is a bug where DuplicateHandle(h, FALSE) makes the
// new handle inheritable if the old handle was inheritable.
printTestName(__FUNCTION__);
Worker p;
auto n = p.newBuffer(FALSE);
@ -49,17 +49,17 @@ static void Test_IntrinsicInheritFlags() {
CHECK(pipeN.inheritable() == false);
}
REGISTER(Test_Input_Vs_Output, always);
static void Test_Input_Vs_Output() {
// Ensure that APIs meant for the other kind of handle fail.
printTestName(__FUNCTION__);
Worker p;
CHECK(!p.getStdin().tryScreenBufferInfo());
CHECK(!p.getStdout().tryNumberOfConsoleInputEvents());
}
REGISTER(Test_Detach_Does_Not_Change_Standard_Handles, always);
static void Test_Detach_Does_Not_Change_Standard_Handles() {
// Detaching the current console does not affect the standard handles.
printTestName(__FUNCTION__);
auto check = [](Worker &p) {
auto handles1 = handleValues(stdHandles(p));
p.detach();
@ -92,6 +92,7 @@ static void Test_Detach_Does_Not_Change_Standard_Handles() {
}
}
REGISTER(Test_Activate_Does_Not_Change_Standard_Handles, always);
static void Test_Activate_Does_Not_Change_Standard_Handles() {
// SetConsoleActiveScreenBuffer does not change the standard handles.
// MSDN documents this fact on "Console Handles"[1]
@ -101,7 +102,6 @@ static void Test_Activate_Does_Not_Change_Standard_Handles() {
// change the STDOUT handle does not affect the active screen buffer."
//
// [1] https://msdn.microsoft.com/en-us/library/windows/desktop/ms682075.aspx
printTestName(__FUNCTION__);
Worker p;
auto handles1 = handleValues(stdHandles(p));
p.newBuffer(TRUE).activate();
@ -109,6 +109,7 @@ static void Test_Activate_Does_Not_Change_Standard_Handles() {
CHECK(handles1 == handles2);
}
REGISTER(Test_Active_ScreenBuffer_Order, always);
static void Test_Active_ScreenBuffer_Order() {
// SetActiveConsoleScreenBuffer does not increase a refcount on the
// screen buffer. Instead, when the active screen buffer's refcount hits
@ -121,7 +122,6 @@ static void Test_Active_ScreenBuffer_Order() {
return ret;
};
printTestName(__FUNCTION__);
{
// Simplest test
Worker p;
@ -155,6 +155,7 @@ static void Test_Active_ScreenBuffer_Order() {
}
}
REGISTER(Test_GetStdHandle_SetStdHandle, always);
static void Test_GetStdHandle_SetStdHandle() {
// A commenter on the Old New Thing blog suggested that
// GetStdHandle/SetStdHandle could have internally used CloseHandle and/or
@ -164,7 +165,6 @@ static void Test_GetStdHandle_SetStdHandle() {
// fact.
//
// http://blogs.msdn.com/b/oldnewthing/archive/2013/03/07/10399690.aspx#10400489
printTestName(__FUNCTION__);
auto &hv = handleValues;
{
// Set values and read them back. We get the same handles.
@ -192,13 +192,3 @@ static void Test_GetStdHandle_SetStdHandle() {
CHECK_EQ(p.openConout().firstChar(), 'b');
}
}
REGISTER(run_MiscTests, always);
void run_MiscTests() {
Test_IntrinsicInheritFlags();
Test_Input_Vs_Output();
Test_Detach_Does_Not_Change_Standard_Handles();
Test_Activate_Does_Not_Change_Standard_Handles();
Test_Active_ScreenBuffer_Order();
Test_GetStdHandle_SetStdHandle();
}

View File

@ -1,5 +1 @@
#include <TestCommon.h>
REGISTER(run_Modern, isModernConio);
void run_Modern() {
}

View File

@ -18,12 +18,12 @@ static void checkAttachHandleSet(Worker &child, Worker &source) {
CHECK(false && "checkAttachHandleSet failed");
}
REGISTER(Test_HandleDuplication, isTraditionalConio);
static void Test_HandleDuplication() {
// A traditional console handle cannot be duplicated to another process,
// and it must be duplicated using the GetConsoleProcess() pseudo-value.
// (This tests targetProcess != psuedo-value, but it doesn't test
// sourceProcess != pseudo-value. Not worth the trouble.)
printTestName(__FUNCTION__);
Worker p, other;
p.getStdout().setFirstChar('x');
CHECK_EQ(p.getStdout().dup().firstChar(), 'x');
@ -31,9 +31,9 @@ static void Test_HandleDuplication() {
CHECK_EQ(p.getStdout().dup(other).value(), INVALID_HANDLE_VALUE);
}
REGISTER(Test_NewConsole_Resets_ConsoleHandleSet, isTraditionalConio);
static void Test_NewConsole_Resets_ConsoleHandleSet() {
// Test that creating a new console properly resets everything.
printTestName(__FUNCTION__);
Worker p;
// Open some handles to demonstrate the "clean slate" outcome.
@ -82,10 +82,10 @@ static void Test_NewConsole_Resets_ConsoleHandleSet() {
checkClean(p);
}
REGISTER(Test_CreateProcess_DetachedProcess, isTraditionalConio);
static void Test_CreateProcess_DetachedProcess() {
// A child with DETACHED_PROCESS has no console, and its standard handles
// are set to 0 by default.
printTestName(__FUNCTION__);
Worker p;
p.getStdin().dup(TRUE).setStdin();
@ -115,10 +115,10 @@ static void Test_CreateProcess_DetachedProcess() {
}));
}
REGISTER(Test_Creation_bInheritHandles_Flag, isTraditionalConio);
static void Test_Creation_bInheritHandles_Flag() {
// The bInheritHandles flags to CreateProcess has no effect on console
// handles.
printTestName(__FUNCTION__);
Worker p;
for (auto &h : (Handle[]){
p.getStdin(),
@ -137,9 +137,9 @@ static void Test_Creation_bInheritHandles_Flag() {
CHECK(hv(cN.scanForConsoleHandles()) == hv(inheritableHandles(p.scanForConsoleHandles())));
}
REGISTER(Test_HandleAllocationOrder, isTraditionalConio);
static void Test_HandleAllocationOrder() {
// When a new handle is created, it always assumes the lowest unused value.
printTestName(__FUNCTION__);
Worker p;
auto h3 = p.getStdin();
@ -171,12 +171,12 @@ static void Test_HandleAllocationOrder() {
CHECK(h1b.uvalue() == 0x1b);
}
REGISTER(Test_InheritNothing, isTraditionalConio);
static void Test_InheritNothing() {
// It's possible for the standard handles to be non-inheritable.
//
// Avoid calling DuplicateHandle(h, FALSE), because it produces inheritable
// console handles on Windows 7.
printTestName(__FUNCTION__);
Worker p;
auto conin = p.openConin();
auto conout = p.openConout();
@ -201,8 +201,8 @@ static void Test_InheritNothing() {
CHECK(c.newBuffer().value() != INVALID_HANDLE_VALUE);
}
REGISTER(Test_AttachConsole_And_CreateProcess_Inheritance, isTraditionalConio);
static void Test_AttachConsole_And_CreateProcess_Inheritance() {
printTestName(__FUNCTION__);
Worker p;
Worker unrelated({ false, DETACHED_PROCESS });
@ -248,11 +248,11 @@ static void Test_AttachConsole_And_CreateProcess_Inheritance() {
checkAttachHandleSet(unrelated, p);
}
REGISTER(Test_Detach_Implicitly_Closes_Handles, isTraditionalConio);
static void Test_Detach_Implicitly_Closes_Handles() {
// After detaching, calling GetHandleInformation fails on previous console
// handles.
printTestName(__FUNCTION__);
Worker p;
Handle orig[] = {
p.getStdin(),
@ -270,15 +270,3 @@ static void Test_Detach_Implicitly_Closes_Handles() {
CHECK(!h.tryFlags());
}
}
REGISTER(run_Traditional, isTraditionalConio);
void run_Traditional() {
Test_HandleDuplication();
Test_NewConsole_Resets_ConsoleHandleSet();
Test_CreateProcess_DetachedProcess();
Test_Creation_bInheritHandles_Flag();
Test_HandleAllocationOrder();
Test_InheritNothing();
Test_AttachConsole_And_CreateProcess_Inheritance();
Test_Detach_Implicitly_Closes_Handles();
}

View File

@ -1,6 +1,7 @@
#include "TestUtil.h"
#include <array>
#include <iostream>
#include <string>
#include <vector>
@ -96,6 +97,10 @@ void registerTest(const std::string &name, bool (&cond)(), void (&func)()) {
if (g_testFunctions == nullptr) {
g_testFunctions = new RegistrationTable {};
}
for (auto &entry : *g_testFunctions) {
// I think the compiler catches duplicates already, but just in case.
ASSERT(&cond != std::get<1>(entry) || &func != std::get<2>(entry));
}
g_testFunctions->push_back(std::make_tuple(name, &cond, &func));
}

View File

@ -37,7 +37,7 @@ class RemoteWorker;
#define REGISTER(name, cond) \
static void name(); \
int g_register_ ## name = (registerTest(#name, cond, name), 0);
int g_register_ ## cond ## _ ## name = (registerTest(#name, cond, name), 0)
// Test registration
void registerTest(const std::string &name, bool(&cond)(), void(&func)());