Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit tests for query_initialized #45

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test/shmemx/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ check_PROGRAMS += \
c11_test_shmem_ibput \
c11_test_shmem_ibget \
perf_counter \
query_initialized \
shmemx_team_node \
shmem_malloc_with_hints \
signal_add \
Expand Down
84 changes: 84 additions & 0 deletions test/shmemx/query_initialized.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright (c) 2024 Intel Corporation. All rights reserved.
* This software is available to you under the BSD license below:
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* - Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer.
*
* - Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#include <stdio.h>
#include <shmem.h>

int main(int argc, char* argv[])
{
int initialized;
int init_count = 3;
int finalize_count = 3;
int inits_done = 0;
int finalizes_done = 0;

// Check if SHMEM is initialized before calling init
shmem_query_initialized(&initialized);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this should probably be shmemx_query_initialized... At least for tests-sos v1.5.x.

If we go that route, then this test wouldn't build against your SOS implementation of course, but I think that's ok temporarily during our transition to v1.6.x.

I think let's keep the test this way (shmem_) until we are ready to merge Sandia-OpenSHMEM/SOS#1144. Then we can test against this? Although, I'm not certain our CI covers shmemx very well... will have to check.

Sorry for the confusion...

if (initialized != 0) {
printf("ERR: Query_initialized not initially returning 0\n");
return 1;
}

// Initialize SHMEM multiple times
for (int i = 0; i < init_count; i++) {
shmem_init();
inits_done++;

shmem_query_initialized(&initialized);
if (initialized == 0) {
printf("ERR: Initialization failed on iteration %d\n", i + 1);
return 1;
}
}

// Finalize SHMEM multiple times
for (int i = 0; i < finalize_count; i++) {
shmem_finalize();
finalizes_done++;

shmem_query_initialized(&initialized);

if (inits_done > finalizes_done && initialized == 0) {
printf("ERR: SHMEM should still be initialized after finalize iteration %d\n", i + 1);
return 1;
} else if (initialized != 0) {
printf("ERR: SHMEM should be finalized after finalize iteration %d\n", i + 1);
return 1;
}
}

// Verify that init can be called again after finalizing
shmem_init();
shmem_query_initialized(&initialized);
if (initialized == 0) {
printf("ERR: Re-initialization failed after finalization. Expected SHMEM to be initialized again.\n");
return 1;
}

shmem_finalize();
return 0;
}