s4-torture Enable libnetapi and libsmbclient tests using combined build
authorAndrew Bartlett <abartlet@samba.org>
Tue, 10 May 2011 20:12:52 +0000 (22:12 +0200)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 21 Jun 2011 01:29:35 +0000 (11:29 +1000)
Because we now always build the source3 code, we can link directly
against a private libnetapi and libsmbclient to test the behaviour of
these important APIs.

We use a private libnetapi_net_init(), and by using this interface
rather than the public one, we can ensure that the correct smb.conf is
loaded (as smbtorture4 is a Samba4 semantics binary).

The #include of the source3 includes.h is required to do the manual
lp_load().

Andrew Bartlett

source4/torture/libnetapi/libnetapi.c
source4/torture/libnetapi/wscript_build
source4/torture/libsmbclient/wscript_build
source4/torture/torture.c

index 633dc6cc3e39d85e8cbc4725ef7674d6a3d60288..92c7b3a394e0e80a7a94f7d5c4c3cd5abfd3be9d 100644 (file)
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#include "includes.h"
+#include "source3/include/includes.h"
 #include "torture/smbtorture.h"
 #include "auth/credentials/credentials.h"
 #include "lib/cmdline/popt_common.h"
-#include <netapi.h>
+#include "source3/lib/netapi/netapi.h"
+#include "source3/lib/netapi/netapi_private.h"
+#include "source4/param/param.h"
 #include "torture/libnetapi/proto.h"
 
 bool torture_libnetapi_init_context(struct torture_context *tctx,
@@ -30,13 +32,19 @@ bool torture_libnetapi_init_context(struct torture_context *tctx,
        NET_API_STATUS status;
        struct libnetapi_ctx *ctx;
 
-       status = libnetapi_init(&ctx);
+       if (!lp_load(lpcfg_configfile(tctx->lp_ctx), true, false, false, true)) {
+               fprintf(stderr, "error loading %s\n", lpcfg_configfile(tctx->lp_ctx));
+               return W_ERROR_V(WERR_GENERAL_FAILURE);
+       }
+
+       init_names();
+       load_interfaces();
+
+       status = libnetapi_net_init(&ctx);
        if (status != 0) {
                return false;
        }
 
-       libnetapi_set_debuglevel(ctx,
-               talloc_asprintf(ctx, "%d", DEBUGLEVEL));
        libnetapi_set_username(ctx,
                cli_credentials_get_username(cmdline_credentials));
        libnetapi_set_password(ctx,
@@ -52,10 +60,16 @@ static bool torture_libnetapi_initialize(struct torture_context *tctx)
         NET_API_STATUS status;
        struct libnetapi_ctx *ctx;
 
+       /* We must do this first, as otherwise we fail if we don't
+        * have an smb.conf in the default path (we need to use the
+        * torture smb.conf */
+       torture_assert(tctx, torture_libnetapi_init_context(tctx, &ctx),
+                      "failed to initialize libnetapi");
+
        status = libnetapi_init(&ctx);
-       if (status != 0) {
-               return false;
-       }
+
+       torture_assert(tctx, ctx != NULL, "Failed to get a libnetapi_ctx");
+       torture_assert_int_equal(tctx, status, 0, "libnetapi_init failed despite alredy being set up");
 
        libnetapi_free(ctx);
 
index a087c96662d2211d0838082eee3a8b43415d2b98..4f579c9820d8e0923630e4ccef1ff0b1ba59bb0b 100644 (file)
@@ -5,8 +5,7 @@ bld.SAMBA_MODULE('TORTURE_LIBNETAPI',
        autoproto='proto.h',
        subsystem='smbtorture',
        init_function='torture_libnetapi_init',
-       deps='POPT_CREDENTIALS NETAPI',
+       deps='POPT_CREDENTIALS netapi',
        internal_module=True,
-        enabled=False
        )
 
index 8f93487389f07d670825258e113a6f61bc04220d..8b2c516dbfcdc74eef1c7764f83dd7fb5bc788b8 100644 (file)
@@ -6,9 +6,8 @@ bld.SAMBA_MODULE('TORTURE_LIBSMBCLIENT',
        autoproto='proto.h',
        subsystem='smbtorture',
        init_function='torture_libsmbclient_init',
-       deps='POPT_CREDENTIALS SMBCLIENT',
-       internal_module=True,
-        enabled=False
+       deps='POPT_CREDENTIALS libsmb/smbclient',
+       internal_module=True
        )
 
 
index 3dae9f586328a34e2618bbfaa6cac3e9be50f940..9b1719ed7d677326391a6d1dc2d753aaca760b2b 100644 (file)
@@ -43,20 +43,6 @@ bool torture_register_suite(struct torture_suite *suite)
        return torture_suite_add_suite(torture_root, suite);
 }
 
-#ifndef ENABLE_LIBNETAPI
-NTSTATUS torture_libnetapi_init(void)
-{
-       return NT_STATUS_OK;
-}
-#endif
-
-#ifndef ENABLE_LIBSMBCLIENT
-NTSTATUS torture_libsmbclient_init(void)
-{
-       return NT_STATUS_OK;
-}
-#endif
-
 _PUBLIC_ int torture_init(void)
 {
 #define _MODULE_PROTO(init) extern NTSTATUS init(void);