Isabella Bosia : ndis.sys/tests: Add tests for ndis ioctls.

Alexandre Julliard julliard at winehq.org
Thu Sep 3 15:26:46 CDT 2020


Module: wine
Branch: master
Commit: b8d710ce687045cca2d66d7a23b3688939935983
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=b8d710ce687045cca2d66d7a23b3688939935983

Author: Isabella Bosia <ibosia at codeweavers.com>
Date:   Tue Sep  1 12:41:20 2020 +0100

ndis.sys/tests: Add tests for ndis ioctls.

Signed-off-by: Isabella Bosia <ibosia at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 configure                       |   1 +
 configure.ac                    |   1 +
 dlls/ndis.sys/tests/Makefile.in |   5 ++
 dlls/ndis.sys/tests/ndis.c      | 146 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 153 insertions(+)

diff --git a/configure b/configure
index 96730fce69..538218fda1 100755
--- a/configure
+++ b/configure
@@ -21057,6 +21057,7 @@ wine_fn_config_makefile dlls/mtxdm enable_mtxdm
 wine_fn_config_makefile dlls/ncrypt enable_ncrypt
 wine_fn_config_makefile dlls/nddeapi enable_nddeapi
 wine_fn_config_makefile dlls/ndis.sys enable_ndis_sys
+wine_fn_config_makefile dlls/ndis.sys/tests enable_tests
 wine_fn_config_makefile dlls/netapi32 enable_netapi32
 wine_fn_config_makefile dlls/netapi32/tests enable_tests
 wine_fn_config_makefile dlls/netcfgx enable_netcfgx
diff --git a/configure.ac b/configure.ac
index 13adf2da7e..f60cd59354 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3579,6 +3579,7 @@ WINE_CONFIG_MAKEFILE(dlls/mtxdm)
 WINE_CONFIG_MAKEFILE(dlls/ncrypt)
 WINE_CONFIG_MAKEFILE(dlls/nddeapi)
 WINE_CONFIG_MAKEFILE(dlls/ndis.sys)
+WINE_CONFIG_MAKEFILE(dlls/ndis.sys/tests)
 WINE_CONFIG_MAKEFILE(dlls/netapi32)
 WINE_CONFIG_MAKEFILE(dlls/netapi32/tests)
 WINE_CONFIG_MAKEFILE(dlls/netcfgx)
diff --git a/dlls/ndis.sys/tests/Makefile.in b/dlls/ndis.sys/tests/Makefile.in
new file mode 100644
index 0000000000..8544dfdff2
--- /dev/null
+++ b/dlls/ndis.sys/tests/Makefile.in
@@ -0,0 +1,5 @@
+TESTDLL   = ndis.sys
+IMPORTS   = iphlpapi advapi32 ole32
+
+C_SRCS = \
+	ndis.c
diff --git a/dlls/ndis.sys/tests/ndis.c b/dlls/ndis.sys/tests/ndis.c
new file mode 100644
index 0000000000..679d29130c
--- /dev/null
+++ b/dlls/ndis.sys/tests/ndis.c
@@ -0,0 +1,146 @@
+/*
+ * Unit tests for ndis ioctls
+ *
+ * Copyright (c) 2020 Isabella Bosia
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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 GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <ntstatus.h>
+#define WIN32_NO_STATUS
+#include <windows.h>
+#include <winioctl.h>
+#include <ntddndis.h>
+#include <winsock2.h>
+#include <ws2ipdef.h>
+#include <iphlpapi.h>
+#include <netioapi.h>
+#include <shlwapi.h>
+#include <stdio.h>
+#include <string.h>
+#include <winternl.h>
+#include <winnt.h>
+#include "wine/test.h"
+
+static void test_device(const WCHAR *service_name, const MIB_IF_ROW2 *row)
+{
+    DWORD size;
+    int ret;
+    NDIS_MEDIUM medium;
+    UCHAR addr[IF_MAX_PHYS_ADDRESS_LENGTH];
+    HANDLE netdev = INVALID_HANDLE_VALUE;
+    int oid;
+    UNICODE_STRING str;
+    OBJECT_ATTRIBUTES attr;
+    NTSTATUS status;
+    IO_STATUS_BLOCK iosb;
+    WCHAR meoW[47];
+
+    swprintf( meoW, ARRAY_SIZE(meoW), L"\\Device\\%s", service_name );
+    RtlInitUnicodeString( &str, meoW );
+    InitializeObjectAttributes( &attr, &str, 0, 0, NULL );
+    status = NtOpenFile( &netdev, GENERIC_READ, &attr, &iosb, FILE_SHARE_READ, 0 );
+
+    if (status != STATUS_SUCCESS)
+    {
+        skip( "Couldn't open the device (status = %d)\n", status );
+        return;
+    }
+
+    oid = OID_GEN_MEDIA_SUPPORTED;
+    ret = DeviceIoControl( netdev, IOCTL_NDIS_QUERY_GLOBAL_STATS,
+            &oid, sizeof(oid), &medium, sizeof(medium), &size, NULL );
+    ok( ret, "OID_GEN_MEDIA_SUPPORTED failed (ret = %d)\n", ret );
+    ok( medium == row->MediaType, "Wrong media type\n" );
+
+    oid = OID_GEN_MEDIA_IN_USE;
+    ret = DeviceIoControl( netdev, IOCTL_NDIS_QUERY_GLOBAL_STATS,
+            &oid, sizeof(oid), &medium, sizeof(medium), &size, NULL );
+    ok( ret, "OID_GEN_MEDIA_IN_USE failed (ret = %d)\n", ret );
+    ok( medium == row->MediaType, "Wrong media type\n" );
+
+    oid = OID_802_3_PERMANENT_ADDRESS;
+    ret = DeviceIoControl( netdev, IOCTL_NDIS_QUERY_GLOBAL_STATS,
+            &oid, sizeof(oid), addr, sizeof(addr), &size, NULL );
+    ok( ret, "OID_802_3_PERMANENT_ADDRESS failed (ret = %d)\n", ret );
+    ok( row->PhysicalAddressLength == size && !memcmp( row->PermanentPhysicalAddress, addr, size ),
+            "Wrong permanent address\n" );
+
+    oid = OID_802_3_CURRENT_ADDRESS;
+    ret = DeviceIoControl( netdev, IOCTL_NDIS_QUERY_GLOBAL_STATS,
+            &oid, sizeof(oid), addr, sizeof(addr), &size, NULL );
+    ok( ret, "OID_802_3_CURRENT_ADDRESS failed (ret = %d)\n", ret );
+    ok( row->PhysicalAddressLength == size && !memcmp( row->PhysicalAddress, addr, size ),
+            "Wrong current address\n" );
+}
+
+static void test_ndis_ioctl(void)
+{
+    HKEY nics, sub_key;
+    LSTATUS ret;
+    WCHAR card[16];
+    WCHAR description[100], service_name[100];
+    DWORD size, type, i = 0;
+
+    ret = RegOpenKeyExW( HKEY_LOCAL_MACHINE,
+            L"Software\\Microsoft\\Windows NT\\CurrentVersion\\NetworkCards", 0, KEY_READ, &nics );
+    ok( ret == ERROR_SUCCESS, "NetworkCards key missing\n" );
+
+    while (1)
+    {
+        MIB_IF_ROW2 row = {{0}};
+        GUID guid;
+
+        size = sizeof(card);
+        ret = RegEnumKeyExW( nics, i, card, &size, NULL, NULL, NULL, NULL );
+        if (ret != ERROR_SUCCESS)
+            break;
+        i++;
+
+        ret = RegOpenKeyExW( nics, card, 0, KEY_READ, &sub_key );
+        ok( ret == ERROR_SUCCESS, "Could not open network card subkey\n" );
+
+        size = sizeof(service_name);
+        ret = RegQueryValueExW( sub_key, L"ServiceName", NULL, &type, (BYTE *)service_name, &size );
+        ok( ret == ERROR_SUCCESS && type == REG_SZ, "Wrong ServiceName\n" );
+
+        CLSIDFromString( service_name, (LPCLSID)&guid );
+        ConvertInterfaceGuidToLuid( &guid, &row.InterfaceLuid );
+
+        ret = GetIfEntry2(&row);
+        ok( ret == NO_ERROR, "GetIfEntry2 failed\n" );
+
+        ok( IsEqualGUID( &guid, &row.InterfaceGuid ), "Wrong ServiceName\n" );
+
+        size = sizeof(description);
+        ret = RegQueryValueExW( sub_key, L"Description", NULL, &type, (BYTE *)description, &size );
+        ok( ret == ERROR_SUCCESS && type == REG_SZ, "Wrong Description\n" );
+
+        trace( "testing device <%s>\n", wine_dbgstr_w(description) );
+        test_device( service_name, &row );
+
+        RegCloseKey( sub_key );
+    }
+
+    if (i == 0)
+        skip( "Network card subkeys missing\n" );
+
+    RegCloseKey( nics );
+}
+
+START_TEST(ndis)
+{
+    test_ndis_ioctl();
+}




More information about the wine-cvs mailing list