114137Sbrandon.potter@amd.com/*
214137Sbrandon.potter@amd.com * Copyright (c) 2011-2015 Advanced Micro Devices, Inc.
314137Sbrandon.potter@amd.com * All rights reserved.
414137Sbrandon.potter@amd.com *
514137Sbrandon.potter@amd.com * For use for simulation and test purposes only
614137Sbrandon.potter@amd.com *
714137Sbrandon.potter@amd.com * Redistribution and use in source and binary forms, with or without
814137Sbrandon.potter@amd.com * modification, are permitted provided that the following conditions are met:
914137Sbrandon.potter@amd.com *
1014137Sbrandon.potter@amd.com * 1. Redistributions of source code must retain the above copyright notice,
1114137Sbrandon.potter@amd.com * this list of conditions and the following disclaimer.
1214137Sbrandon.potter@amd.com *
1314137Sbrandon.potter@amd.com * 2. Redistributions in binary form must reproduce the above copyright notice,
1414137Sbrandon.potter@amd.com * this list of conditions and the following disclaimer in the documentation
1514137Sbrandon.potter@amd.com * and/or other materials provided with the distribution.
1614137Sbrandon.potter@amd.com *
1714137Sbrandon.potter@amd.com * 3. Neither the name of the copyright holder nor the names of its
1814137Sbrandon.potter@amd.com * contributors may be used to endorse or promote products derived from this
1914137Sbrandon.potter@amd.com * software without specific prior written permission.
2014137Sbrandon.potter@amd.com *
2114137Sbrandon.potter@amd.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2214137Sbrandon.potter@amd.com * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2314137Sbrandon.potter@amd.com * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2414137Sbrandon.potter@amd.com * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
2514137Sbrandon.potter@amd.com * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2614137Sbrandon.potter@amd.com * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2714137Sbrandon.potter@amd.com * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2814137Sbrandon.potter@amd.com * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2914137Sbrandon.potter@amd.com * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3014137Sbrandon.potter@amd.com * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3114137Sbrandon.potter@amd.com * POSSIBILITY OF SUCH DAMAGE.
3214137Sbrandon.potter@amd.com *
3314137Sbrandon.potter@amd.com * Authors: Brandon Potter,
3414137Sbrandon.potter@amd.com *          John Alsop
3514137Sbrandon.potter@amd.com */
3614137Sbrandon.potter@amd.com
3714137Sbrandon.potter@amd.com#include <linux/limits.h>
3814137Sbrandon.potter@amd.com#include <stdio.h>
3914137Sbrandon.potter@amd.com#include <stdlib.h>
4014137Sbrandon.potter@amd.com#include <string.h>
4114137Sbrandon.potter@amd.com#include <unistd.h>
4214137Sbrandon.potter@amd.com
4314137Sbrandon.potter@amd.comconst int BUFFER_SIZE = 64;
4414137Sbrandon.potter@amd.com
4514137Sbrandon.potter@amd.com// Tests the functionality of RegisterFilesystem
4614137Sbrandon.potter@amd.comint main(void)
4714137Sbrandon.potter@amd.com{
4814137Sbrandon.potter@amd.com    char *cwd = getcwd(NULL, PATH_MAX);
4914137Sbrandon.potter@amd.com    printf("cwd: %s\n", cwd);
5014137Sbrandon.potter@amd.com    free(cwd);
5114137Sbrandon.potter@amd.com
5214137Sbrandon.potter@amd.com    chdir("/proc");
5314137Sbrandon.potter@amd.com
5414137Sbrandon.potter@amd.com    cwd = getcwd(NULL, PATH_MAX);
5514137Sbrandon.potter@amd.com    printf("cwd: %s\n", cwd);
5614137Sbrandon.potter@amd.com    free(cwd);
5714137Sbrandon.potter@amd.com
5814137Sbrandon.potter@amd.com    FILE *fp;
5914137Sbrandon.potter@amd.com    char buffer[BUFFER_SIZE];
6014137Sbrandon.potter@amd.com
6114137Sbrandon.potter@amd.com    bool found_procline = false;
6214137Sbrandon.potter@amd.com    fp = popen("cat cpuinfo", "r");
6314137Sbrandon.potter@amd.com    if (fp != NULL) {
6414137Sbrandon.potter@amd.com        while (fgets(buffer, BUFFER_SIZE, fp) != NULL) {
6514137Sbrandon.potter@amd.com            printf("%s", buffer);
6614137Sbrandon.potter@amd.com            if (strstr(buffer, "processor")) {
6714137Sbrandon.potter@amd.com                found_procline = true;
6814137Sbrandon.potter@amd.com            }
6914137Sbrandon.potter@amd.com        }
7014137Sbrandon.potter@amd.com        pclose(fp);
7114137Sbrandon.potter@amd.com    }
7214137Sbrandon.potter@amd.com
7314137Sbrandon.potter@amd.com    if (found_procline) {
7414137Sbrandon.potter@amd.com        printf("SUCCESS\n");
7514137Sbrandon.potter@amd.com        return EXIT_SUCCESS;
7614137Sbrandon.potter@amd.com    }
7714137Sbrandon.potter@amd.com
7814137Sbrandon.potter@amd.com    printf("FAILURE\n");
7914137Sbrandon.potter@amd.com    return EXIT_FAILURE;
8014137Sbrandon.potter@amd.com}
81