From 66859eaeb94c308db693e6f1ef902be35d059d76 Mon Sep 17 00:00:00 2001 From: Albert Chu Date: Thu, 8 Feb 2018 14:48:57 -0800 Subject: [PATCH] t/kvs: Add fence_invalid test Add test to ensure fence captures an invalid flag/nproc value. --- t/Makefile.am | 6 ++ t/kvs/fence_invalid.c | 137 ++++++++++++++++++++++++++++++++++++++++ t/t1001-kvs-internals.t | 14 ++++ 3 files changed, 157 insertions(+) create mode 100644 t/kvs/fence_invalid.c diff --git a/t/Makefile.am b/t/Makefile.am index ad68a10be4e9..b20116e2afd6 100644 --- a/t/Makefile.am +++ b/t/Makefile.am @@ -186,6 +186,7 @@ check_PROGRAMS = \ kvs/commit \ kvs/commitmerge \ kvs/fence_namespace_remove \ + kvs/fence_invalid \ module/basic \ request/treq \ barrier/tbarrier @@ -313,6 +314,11 @@ kvs_fence_namespace_remove_CPPFLAGS = $(test_cppflags) kvs_fence_namespace_remove_LDADD = \ $(test_ldadd) $(LIBDL) $(LIBUTIL) +kvs_fence_invalid_SOURCES = kvs/fence_invalid.c +kvs_fence_invalid_CPPFLAGS = $(test_cppflags) +kvs_fence_invalid_LDADD = \ + $(test_ldadd) $(LIBDL) $(LIBUTIL) + kvs_watch_disconnect_SOURCES = kvs/watch_disconnect.c kvs_watch_disconnect_CPPFLAGS = $(test_cppflags) kvs_watch_disconnect_LDADD = \ diff --git a/t/kvs/fence_invalid.c b/t/kvs/fence_invalid.c new file mode 100644 index 000000000000..c147df4805d6 --- /dev/null +++ b/t/kvs/fence_invalid.c @@ -0,0 +1,137 @@ +/*****************************************************************************\ + * Copyright (c) 2014 Lawrence Livermore National Security, LLC. Produced at + * the Lawrence Livermore National Laboratory (cf, AUTHORS, DISCLAIMER.LLNS). + * LLNL-CODE-658032 All rights reserved. + * + * This file is part of the Flux resource manager framework. + * For details, see https://github.com/flux-framework. + * + * 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 2 of the license, or (at your option) + * any later version. + * + * Flux 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 terms and conditions of 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, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + * See also: http://www.gnu.org/licenses/ +\*****************************************************************************/ + +#if HAVE_CONFIG_H +#include "config.h" +#endif +#include +#include +#include +#include +#include +#include +#include +#include + +#include "src/common/libutil/oom.h" +#include "src/common/libutil/log.h" +#include "src/common/libutil/xzmalloc.h" +#include "src/common/libutil/monotime.h" +#include "src/common/libutil/tstat.h" + +static char *prefix = NULL; + +static void usage (void) +{ + fprintf (stderr, "Usage: fence_invalid prefix\n"); + exit (1); +} + +int main (int argc, char *argv[]) +{ + flux_t *h = NULL; + char *fence_name = NULL; + uint32_t rank; + char *key1 = NULL; + char *key2 = NULL; + flux_future_t *f1 = NULL; + flux_future_t *f2 = NULL; + flux_kvs_txn_t *txn1 = NULL; + flux_kvs_txn_t *txn2 = NULL; + + log_init (basename (argv[0])); + + if (argc != 2) + usage (); + + prefix = argv[1]; + + if (!(h = flux_open (NULL, 0))) { + log_err_exit ("flux_open"); + goto done; + } + + if (flux_get_rank (h, &rank) < 0) { + log_err ("flux_get_rank"); + goto done; + } + + if (!(txn1 = flux_kvs_txn_create ())) { + log_err ("flux_kvs_txn_create"); + goto done; + } + + if (!(txn2 = flux_kvs_txn_create ())) { + log_err ("flux_kvs_txn_create"); + goto done; + } + + fence_name = xasprintf ("%s-%d", prefix, rank); + key1 = xasprintf ("%s.1.%d", prefix, rank); + key2 = xasprintf ("%s.2.%d", prefix, rank); + + if (flux_kvs_txn_pack (txn1, 0, key1, "i", 42) < 0) { + log_err ("%s: flux_kvs_txn_pack", key1); + goto done; + } + + if (flux_kvs_txn_pack (txn2, 0, key2, "i", 42) < 0) { + log_err ("%s: flux_kvs_txn_pack", key2); + goto done; + } + + /* alter flags to generate an error on second fence */ + + if (!(f1 = flux_kvs_fence (h, 0x1, fence_name, 2, txn1))) { + log_err ("flux_kvs_fence"); + goto done; + } + + if (!(f2 = flux_kvs_fence (h, 0x2, fence_name, 2, txn2))) { + log_err ("flux_kvs_fence"); + goto done; + } + + if (flux_future_get (f2, NULL) < 0) { + printf ("flux_future_get: %s\n", flux_strerror (errno)); + goto done; + } + +done: + flux_future_destroy (f1); + flux_future_destroy (f2); + free (key1); + free (key2); + free (fence_name); + flux_kvs_txn_destroy (txn1); + flux_kvs_txn_destroy (txn2); + flux_close (h); + log_fini (); + + return 0; +} + +/* + * vi:tabstop=4 shiftwidth=4 expandtab + */ diff --git a/t/t1001-kvs-internals.t b/t/t1001-kvs-internals.t index 33ef61aee6a7..e78e13014e15 100755 --- a/t/t1001-kvs-internals.t +++ b/t/t1001-kvs-internals.t @@ -297,4 +297,18 @@ test_expect_success 'kvs: clear stats globally' ' flux exec sh -c "flux module stats kvs | grep no-op | grep -q 0" ' +# +# test invalid fence arguments +# + +test_expect_success 'kvs: test invalid fence arguments on rank 0' ' + ${FLUX_BUILD_DIR}/t/kvs/fence_invalid invalidtest1 > invalid_output && + grep "flux_future_get: Invalid argument" invalid_output +' + +test_expect_success 'kvs: test invalid fence arguments on rank 1' ' + flux exec -r 1 sh -c "${FLUX_BUILD_DIR}/t/kvs/fence_invalid invalidtest2" > invalid_output && + grep "flux_future_get: Invalid argument" invalid_output +' + test_done