Skip to content

Commit

Permalink
prov/sharp: Add mocks for sharp_coll_init and sharp_coll_finalize
Browse files Browse the repository at this point in the history
Add mocks for sharp_coll_init and sharp_coll_finalize.

Signed-off-by: Lukasz Dorau <[email protected]>
  • Loading branch information
ldorau authored and grom72 committed Dec 30, 2022
1 parent a083c30 commit 51e2ea0
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
2 changes: 2 additions & 0 deletions prov/sharp/Makefile.include
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
if HAVE_SHARP
_sharp_files = \
prov/sharp/src/mocks/api/sharp.h \
prov/sharp/src/mocks/api/sharp_mocks.c \
include/ofi_sharp.h \
prov/sharp/src/sharp.h \
prov/sharp/src/sharp_attr.c \
Expand Down
89 changes: 89 additions & 0 deletions prov/sharp/src/mocks/api/sharp_mocks.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright (c) 2022 Intel Corporation. All rights reserved.
*
* This software is available to you under a choice of one of two
* licenses. You may choose to be licensed under the terms of the GNU
* General Public License (GPL) Version 2, available from the file
* COPYING in the main directory of this source tree, or 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 <stdlib.h>
#include <rdma/fi_errno.h>
#include <string.h>

#include "./sharp.h"

/* mock of struct sharp_coll_context */
struct sharp_coll_context {
struct sharp_coll_init_spec mock_content;
};

/**
* @brief SHARP coll context initialization
*
* This routine is initialize SHARP coll library and create @ref sharp_coll_context "SHARP coll context".
* This is a collective, called from all processes of the job.
*
* @warning An application cannot call any SHARP coll routine before sharp_coll_init
*
* @param [in] sharp_coll_spec SHARP coll specification descriptor.
* @param [out] sharp_coll_context Initialized @ref sharp_coll_context "SHARP coll context".
*
* @return Error code as defined by @ref sharp_error_no
*/
int sharp_coll_init(struct sharp_coll_init_spec *sharp_coll_spec,
struct sharp_coll_context **sharp_coll_context)
{
struct sharp_coll_context *context;
context = calloc(1, sizeof(*context));
if (!context)
return -FI_ENOMEM;

memcpy(&context->mock_content, sharp_coll_spec, sizeof(context->mock_content));

*sharp_coll_context = context;

return 0;
}

/**
* @brief SHARP coll context finalize
*
* This routine finalizes and releases the resources associated with
* @ref sharp_coll_context "SHARP coll context". typically done once, just before the process ends.
*
* @warning An application cannot call any SHARP coll routine after sharp_coll_finalize
*
* @param [in] context SHARP coll context to cleanup.
*
* @return Error code as defined by @ref sharp_error_no
*/
int sharp_coll_finalize(struct sharp_coll_context *context)
{
free(context);

return 0;
}

0 comments on commit 51e2ea0

Please sign in to comment.