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