diff options
| author | Ashish Chaudhari <ashish@ettus.com> | 2015-08-10 23:14:20 -0700 | 
|---|---|---|
| committer | Ashish Chaudhari <ashish@ettus.com> | 2015-08-10 23:14:20 -0700 | 
| commit | b5c81677078f56b3e671ebeaca1e3b803c2f4ef9 (patch) | |
| tree | a1b17b4be203331de7e146e94051f26be5a20102 /host/tests/eeprom_c_test.c | |
| parent | 16e149fe6fcc1bc18adea3eeeefad2c7ee93b2e0 (diff) | |
| parent | 28327c8e8a810b19da126116d0dc4c26b643baed (diff) | |
| download | uhd-b5c81677078f56b3e671ebeaca1e3b803c2f4ef9.tar.gz uhd-b5c81677078f56b3e671ebeaca1e3b803c2f4ef9.tar.bz2 uhd-b5c81677078f56b3e671ebeaca1e3b803c2f4ef9.zip | |
Merge branch 'master' into ashish/register_api
Diffstat (limited to 'host/tests/eeprom_c_test.c')
| -rw-r--r-- | host/tests/eeprom_c_test.c | 157 | 
1 files changed, 157 insertions, 0 deletions
| diff --git a/host/tests/eeprom_c_test.c b/host/tests/eeprom_c_test.c new file mode 100644 index 000000000..1b29dfd44 --- /dev/null +++ b/host/tests/eeprom_c_test.c @@ -0,0 +1,157 @@ +// +// Copyright 2015 Ettus Research LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program.  If not, see <http://www.gnu.org/licenses/>. +// + +#include <uhd.h> + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#define UHD_TEST_EXECUTE_OR_GOTO(label, ...) \ +    if(__VA_ARGS__){ \ +        fprintf(stderr, "Error occurred at %s:%d\n", __FILE__, (__LINE__-1)); \ +        return_code = EXIT_FAILURE; \ +        goto label; \ +    } + +#define BUFFER_SIZE 1024 + +int main(){ + +    // Variables +    int return_code; +    uhd_mboard_eeprom_handle mb_eeprom; +    uhd_dboard_eeprom_handle db_eeprom; +    int db_revision; +    char str_buffer[BUFFER_SIZE]; + +    return_code = EXIT_SUCCESS; + +    /* +     * Motherboard EEPROM test +     */ + +    // Create EEPROM handle +    UHD_TEST_EXECUTE_OR_GOTO(end_of_test, +        uhd_mboard_eeprom_make(&mb_eeprom) +    ) + +    // Set a value, retrieve it, and make sure it matches +    UHD_TEST_EXECUTE_OR_GOTO(free_mboard_eeprom, +        uhd_mboard_eeprom_set_value( +            mb_eeprom, +            "serial", +            "F12345" +        ) +    ) +    UHD_TEST_EXECUTE_OR_GOTO(free_mboard_eeprom, +        uhd_mboard_eeprom_get_value( +            mb_eeprom, +            "serial", +            str_buffer, +            BUFFER_SIZE +        ) +    ) +    if(strcmp(str_buffer, "F12345")){ +        return_code = EXIT_FAILURE; +        fprintf(stderr, "%s:%d: Mismatched EEPROM value: \"%s\" vs. \"F12345\"\n", +                        __FILE__, __LINE__, +                        str_buffer); +        goto free_mboard_eeprom; +    } + +    /* +     * Daughterboard EEPROM test +     */ + +    // Create EEPROM handle +    UHD_TEST_EXECUTE_OR_GOTO(free_mboard_eeprom, +        uhd_dboard_eeprom_make(&db_eeprom) +    ) + +    // Set the ID, retrieve it, and make sure it matches +    UHD_TEST_EXECUTE_OR_GOTO(free_dboard_eeprom, +        uhd_dboard_eeprom_set_id(db_eeprom, "0x0067") +    ) +    UHD_TEST_EXECUTE_OR_GOTO(free_dboard_eeprom, +        uhd_dboard_eeprom_get_id( +            db_eeprom, +            str_buffer, +            BUFFER_SIZE +        ) +    ) +    if(strcmp(str_buffer, "0x0067")){ +        return_code = EXIT_FAILURE; +        fprintf(stderr, "%s:%d: Mismatched daughterboard ID: \"%s\" vs. \"0x0067\"\n", +                        __FILE__, __LINE__, +                        str_buffer); +        goto free_dboard_eeprom; +    } + +    // Set the serial, retrieve it, and make sure it matches +    UHD_TEST_EXECUTE_OR_GOTO(free_dboard_eeprom, +        uhd_dboard_eeprom_set_serial(db_eeprom, "F12345") +    ) +    UHD_TEST_EXECUTE_OR_GOTO(free_dboard_eeprom, +        uhd_dboard_eeprom_get_serial( +            db_eeprom, +            str_buffer, +            BUFFER_SIZE +        ) +    ) +    if(strcmp(str_buffer, "F12345")){ +        return_code = EXIT_FAILURE; +        fprintf(stderr, "%s:%d: Mismatched daughterboard serial: \"%s\" vs. \"F12345\"\n", +                        __FILE__, __LINE__, +                        str_buffer); +        goto free_dboard_eeprom; +    } + +    // Set the revision, retrieve it, and make sure it matches +    UHD_TEST_EXECUTE_OR_GOTO(free_dboard_eeprom, +        uhd_dboard_eeprom_set_revision(db_eeprom, 4) +    ) +    UHD_TEST_EXECUTE_OR_GOTO(free_dboard_eeprom, +        uhd_dboard_eeprom_get_revision(db_eeprom, &db_revision) +    ) +    if(db_revision != 4){ +        return_code = EXIT_FAILURE; +        fprintf(stderr, "%s:%d: Mismatched daughterboard revision: \"%d\" vs. 4\n", +                        __FILE__, __LINE__, db_revision); +        goto free_dboard_eeprom; +    } + +    free_dboard_eeprom: +        if(return_code){ +            uhd_dboard_eeprom_last_error(db_eeprom, str_buffer, BUFFER_SIZE); +            fprintf(stderr, "db_eeprom error: %s\n", str_buffer); +        } +	uhd_dboard_eeprom_free(&db_eeprom); + +    free_mboard_eeprom: +        if(return_code){ +            uhd_mboard_eeprom_last_error(mb_eeprom, str_buffer, BUFFER_SIZE); +            fprintf(stderr, "mb_eeprom error: %s\n", str_buffer); +        } +	uhd_mboard_eeprom_free(&mb_eeprom); + +    end_of_test: +        if(!return_code){ +            printf("\nNo errors detected\n"); +        } +        return return_code; +} | 
