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