1 /* 2 * Copyright 2011 Intel Corporation 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 * DEALINGS IN THE SOFTWARE. 22 */ 23 24 /** 25 * \file test.cpp 26 * 27 * Standalone tests for the GLSL compiler. 28 * 29 * This file provides a standalone executable which can be used to 30 * test components of the GLSL. 31 * 32 * Each test is a function with the same signature as main(). The 33 * main function interprets its first argument as the name of the test 34 * to run, strips out that argument, and then calls the test function. 35 */ 36 37 #include <stdio.h> 38 #include <stdlib.h> 39 #include <string.h> 40 41 #include "test_optpass.h" 42 43 /** 44 * Print proper usage and exit with failure. 45 */ 46 static void 47 usage_fail(const char *name) 48 { 49 printf("*** usage: %s <command> <options>\n", name); 50 printf("\n"); 51 printf("Possible commands are:\n"); 52 printf(" optpass: test an optimization pass in isolation\n"); 53 exit(EXIT_FAILURE); 54 } 55 56 static const char *extract_command_from_argv(int *argc, char **argv) 57 { 58 if (*argc < 2) { 59 usage_fail(argv[0]); 60 } 61 const char *command = argv[1]; 62 --*argc; 63 memmove(&argv[1], &argv[2], (*argc) * sizeof(argv[1])); 64 return command; 65 } 66 67 int main(int argc, char **argv) 68 { 69 const char *command = extract_command_from_argv(&argc, argv); 70 if (strcmp(command, "optpass") == 0) { 71 return test_optpass(argc, argv); 72 } else { 73 usage_fail(argv[0]); 74 } 75 76 /* Execution should never reach here. */ 77 return EXIT_FAILURE; 78 } 79