-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
161 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/* | ||
* Copyright (c) Microsoft Corporation. | ||
* Licensed under the MIT license. | ||
*/ | ||
|
||
/*====================================================================================================================* | ||
* Imports * | ||
*====================================================================================================================*/ | ||
|
||
#include <demi/types.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
/*====================================================================================================================* | ||
* Macro Functions * | ||
*====================================================================================================================*/ | ||
|
||
/** | ||
* @brief Returns the maximum of two values. | ||
* | ||
* @param a First value. | ||
* @param b Second value. | ||
* | ||
* @returns The maximum of 'a' and 'b'. | ||
*/ | ||
#define MAX(a, b) (((a) > (b)) ? (a) : (b)) | ||
|
||
/** | ||
* @brief Asserts if 'a' and 'b' agree on size. | ||
* | ||
* @param a Probing size. | ||
* @param b Control size. | ||
* | ||
* @returns Upon success, compilation proceeds as normal. Upon failure, a | ||
* compilation error is generated. | ||
*/ | ||
#define KASSERT_SIZE(a, b) ((void)sizeof(char[(((a) == (b)) ? 1 : -1)])) | ||
|
||
/*====================================================================================================================* | ||
* Private Functions * | ||
*====================================================================================================================*/ | ||
|
||
/** | ||
* @brief tests if @p demi_sgaseg_t has the expected size. | ||
* | ||
* @note This is a compile-time-test. | ||
*/ | ||
static void test_size_sgaseg_t(void) | ||
{ | ||
// The following sizes are intentionally hardcoded. | ||
const size_t SGASEG_BUF_SIZE = 8; | ||
const size_t SGASEG_LEN_SIZE = 4; | ||
const size_t SGASEG_SIZE = SGASEG_BUF_SIZE + SGASEG_LEN_SIZE; | ||
KASSERT_SIZE(sizeof(demi_sgaseg_t), SGASEG_SIZE); | ||
printf("sizeof(demi_sgaseg_t) = %lu\n", sizeof(demi_sgaseg_t)); | ||
} | ||
|
||
/** | ||
* @brief Tests if @p demi_sga_t has the expected size. | ||
* | ||
* @note This is a compile-time-test. | ||
*/ | ||
static void test_size_sga_t(void) | ||
{ | ||
// The following sizes are intentionally hardcoded. | ||
const size_t SGA_BUF_SIZE = 8; | ||
const size_t SGA_NUMSEGS_SIZE = 4; | ||
const size_t SGA_SEGS_SIZE = sizeof(demi_sgaseg_t) * DEMI_SGARRAY_MAXSIZE; | ||
const size_t SGA_ADDR_SIZE = 16; | ||
const size_t SGA_SIZE = SGA_BUF_SIZE + SGA_NUMSEGS_SIZE + SGA_SEGS_SIZE + SGA_ADDR_SIZE; | ||
KASSERT_SIZE(sizeof(demi_sgarray_t), SGA_SIZE); | ||
printf("sizeof(demi_sgarray_t) = %lu\n", sizeof(demi_sgarray_t)); | ||
} | ||
|
||
/** | ||
* @brief Tests if @p demi_accept_result_t has the expected size. | ||
* | ||
* @note This is a compile-time-test. | ||
*/ | ||
static void test_size_demi_accept_result_t(void) | ||
{ | ||
// The following sizes are intentionally hardcoded. | ||
const size_t QD_SIZE = 4; | ||
const size_t SADDR_SIZE = 16; | ||
const size_t RESULT_SIZE = QD_SIZE + SADDR_SIZE; | ||
KASSERT_SIZE(sizeof(demi_accept_result_t), RESULT_SIZE); | ||
printf("sizeof(demi_accept_result_t) = %lu\n", sizeof(demi_accept_result_t)); | ||
} | ||
|
||
/** | ||
* @brief Tests if demi_qresult_t has the expected size. | ||
* | ||
* @note This is a compile-time-test. | ||
*/ | ||
static void test_size_demi_qresult_t(void) | ||
{ | ||
// The following sizes are intentionally hardcoded. | ||
const size_t QR_OPCODE_SIZE = 4; | ||
const size_t QR_QD_SIZE = 4; | ||
const size_t QR_QT_SIZE = 8; | ||
const size_t QR_RET_SIZE = 8; | ||
const size_t QR_VALUE_SIZE = MAX(sizeof(demi_accept_result_t), sizeof(demi_sgarray_t)); | ||
const size_t QR_SIZE = QR_OPCODE_SIZE + QR_QD_SIZE + QR_QT_SIZE + QR_RET_SIZE + QR_VALUE_SIZE; | ||
KASSERT_SIZE(sizeof(demi_qresult_t), QR_SIZE); | ||
printf("sizeof(demi_qresult_t) = %lu\n", sizeof(demi_qresult_t)); | ||
} | ||
|
||
/*====================================================================================================================* | ||
* Public Functions * | ||
*====================================================================================================================*/ | ||
|
||
/** | ||
* @brief Drives the application. | ||
* | ||
* This system-level conducts tests to ensure that the sizes of structures and | ||
* data types exposed by the C bindings of Demikernel are correct. | ||
* | ||
* @param argc Argument count (unused). | ||
* @param argv Argument vector (unused). | ||
* | ||
* @return On successful completion EXIT_SUCCESS is returned. | ||
*/ | ||
int main(int argc, char *const argv[]) | ||
{ | ||
((void)argc); | ||
((void)argv); | ||
|
||
test_size_sgaseg_t(); | ||
test_size_sga_t(); | ||
test_size_demi_accept_result_t(); | ||
test_size_demi_qresult_t(); | ||
|
||
return (EXIT_SUCCESS); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters