hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acmur...@apache.org
Subject svn commit: r1378794 - in /hadoop/common/branches/branch-1-win: ./ src/winutils/tests/
Date Thu, 30 Aug 2012 02:34:47 GMT
Author: acmurthy
Date: Thu Aug 30 02:34:47 2012
New Revision: 1378794

URL: http://svn.apache.org/viewvc?rev=1378794&view=rev
Log:
HADOOP-8453. Added unit tests for winutils. Contributed by Chuan Liu.

Added:
    hadoop/common/branches/branch-1-win/src/winutils/tests/
    hadoop/common/branches/branch-1-win/src/winutils/tests/test-all.bat
    hadoop/common/branches/branch-1-win/src/winutils/tests/test-winutils-basics.bat
    hadoop/common/branches/branch-1-win/src/winutils/tests/test-winutils-chmod.bat
    hadoop/common/branches/branch-1-win/src/winutils/tests/test-winutils-chown.bat
Modified:
    hadoop/common/branches/branch-1-win/CHANGES.branch-1-win.txt
    hadoop/common/branches/branch-1-win/build.xml

Modified: hadoop/common/branches/branch-1-win/CHANGES.branch-1-win.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1-win/CHANGES.branch-1-win.txt?rev=1378794&r1=1378793&r2=1378794&view=diff
==============================================================================
--- hadoop/common/branches/branch-1-win/CHANGES.branch-1-win.txt (original)
+++ hadoop/common/branches/branch-1-win/CHANGES.branch-1-win.txt Thu Aug 30 02:34:47 2012
@@ -69,6 +69,8 @@ branch-hadoop-1-win - unreleased
     MAPREDUCE-4510. Fix needless check/logging of getconf in Windows. (Bikas
     Saha via acmurthy)
 
+    HADOOP-8453. Added unit tests for winutils. (Chuan Liu via acmurthy)
+
 BUG FIXES
 
     HDFS-6527. Backport HADOOP-7389: Use of TestingGroups by tests causes

Modified: hadoop/common/branches/branch-1-win/build.xml
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1-win/build.xml?rev=1378794&r1=1378793&r2=1378794&view=diff
==============================================================================
--- hadoop/common/branches/branch-1-win/build.xml (original)
+++ hadoop/common/branches/branch-1-win/build.xml Thu Aug 30 02:34:47 2012
@@ -136,6 +136,8 @@
 
   <property name="test.libhdfs.conf.dir" value="${c++.libhdfs.src}/tests/conf"/>
   <property name="test.libhdfs.dir" value="${test.build.dir}/libhdfs"/>
+ 
+  <property name="test.winutils.dir" value="${test.build.dir}/winutils/"/>
 
   <property name="librecordio.test.dir" value="${test.build.dir}/librecordio"/>
   <property name="web.src.dir" value="${basedir}/src/web"/>
@@ -626,6 +628,16 @@
     <copy file="${build.winutils}/winutils.exe" todir="${basedir}/bin"/>
   </target>
 
+  <target name="compile-ms-winutils-debug" if="windows">
+    <mkdir dir="${build.winutils}"/>
+
+    <exec dir="${build.winutils}" executable="${msbuild.cmd}" failonerror="true">
+      <arg line="${winutils.src.dir}/winutils.vcxproj /p:Configuration=Debug;OutDir=${build.winutils}/"/>
+    </exec>
+
+    <copy file="${build.winutils}/winutils.exe" todir="${basedir}/bin"/>
+  </target>
+
   <target name="compile-native">
     <antcall target="compile-core-native">
       <param name="compile.native" value="true"/>
@@ -2175,6 +2187,20 @@
     </exec>
   </target>
 
+  <target name="test-ms-winutils" depends="compile-ms-winutils-debug" if="windows">
+    <delete dir="${test.winutils.dir}"/>
+    <mkdir dir="${test.winutils.dir}"/>
+    <copy todir="${test.winutils.dir}">
+      <fileset dir="${winutils.src.dir}\tests" includes="*.bat"/>
+    </copy>
+
+    <exec dir="${test.winutils.dir}"
+      executable="${test.winutils.dir}\test-all.bat"
+      failonerror="true">
+      <env key="HADOOP_HOME" value="${basedir}"/>
+    </exec>
+  </target>
+
 <!-- ================================================================== -->
 <!-- librecordio targets.                                               -->
 <!-- ================================================================== -->		

Added: hadoop/common/branches/branch-1-win/src/winutils/tests/test-all.bat
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1-win/src/winutils/tests/test-all.bat?rev=1378794&view=auto
==============================================================================
--- hadoop/common/branches/branch-1-win/src/winutils/tests/test-all.bat (added)
+++ hadoop/common/branches/branch-1-win/src/winutils/tests/test-all.bat Thu Aug 30 02:34:47
2012
@@ -0,0 +1,19 @@
+:: Licensed to the Apache Software Foundation (ASF) under one or more
+:: contributor license agreements. See the NOTICE file distributed with this
+:: work for additional information regarding copyright ownership. The ASF
+:: licenses this file to you under the Apache License, Version 2.0 (the
+:: "License"); you may not use this file except in compliance with the License.
+:: You may obtain a copy of the License at
+:: 
+:: http://www.apache.org/licenses/LICENSE-2.0
+:: 
+:: Unless required by applicable law or agreed to in writing, software
+:: distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+:: WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+:: License for the specific language governing permissions and limitations under
+:: the License.
+::
+@echo off
+call test-winutils-basics
+call test-winutils-chown
+call test-winutils-chmod

Added: hadoop/common/branches/branch-1-win/src/winutils/tests/test-winutils-basics.bat
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1-win/src/winutils/tests/test-winutils-basics.bat?rev=1378794&view=auto
==============================================================================
--- hadoop/common/branches/branch-1-win/src/winutils/tests/test-winutils-basics.bat (added)
+++ hadoop/common/branches/branch-1-win/src/winutils/tests/test-winutils-basics.bat Thu Aug
30 02:34:47 2012
@@ -0,0 +1,95 @@
+:: Licensed to the Apache Software Foundation (ASF) under one or more
+:: contributor license agreements. See the NOTICE file distributed with this
+:: work for additional information regarding copyright ownership. The ASF
+:: licenses this file to you under the Apache License, Version 2.0 (the
+:: "License"); you may not use this file except in compliance with the License.
+:: You may obtain a copy of the License at
+:: 
+:: http://www.apache.org/licenses/LICENSE-2.0
+:: 
+:: Unless required by applicable law or agreed to in writing, software
+:: distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+:: WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+:: License for the specific language governing permissions and limitations under
+:: the License.
+::
+@echo off
+echo Test most basic security settings are working
+setlocal
+set WINUTILS="%HADOOP_HOME%\bin\winutils.exe"
+set TESTDIR=winutils-test
+
+:: Setup test directory
+::
+if not exist %TESTDIR% md %TESTDIR%
+pushd %TESTDIR%
+
+:: Test cases
+::
+echo Test case 1:
+::  - Create a file.
+::  - Change mode to 377 so owner does not have read permission.
+::  - Verify the owner truly does not have the permissions to read.
+if exist a goto Failure
+type NUL>a
+%WINUTILS% chmod 377 a
+if not %ERRORLEVEL% == 0 goto Failure
+type a
+if %ERRORLEVEL% == 0 goto Failure
+del a
+if not %ERRORLEVEL% == 0 goto Failure
+echo passed.
+
+echo Test case 2:
+::  - Create a file.
+::  - Change mode to 577 so owner does not have write permission.
+::  - Verify the owner truly does not have the permissions to write.
+if exist a goto Failure
+type NUL>a
+%WINUTILS% chmod 577 a
+if not %ERRORLEVEL% == 0 goto Failure
+cmd /C "echo a>>a"
+if %ERRORLEVEL% == 0 goto Failure
+del a
+if not %ERRORLEVEL% == 0 goto Failure
+echo passed.
+
+echo Test case 3:
+::  - Copy WINUTILS to a new executable file, a.exe.
+::  - Change mode to 677 so owner does not have execute permission.
+::  - Verify the owner truly does not have the permissions to execute the file.
+if exist a.exe goto Failure
+copy %WINUTILS% a.exe >NUL
+%WINUTILS% chmod 677 a.exe
+if not %ERRORLEVEL% == 0 goto Failure
+.\a.exe ls
+if %ERRORLEVEL% == 0 goto Failure
+del a.exe
+if not %ERRORLEVEL% == 0 goto Failure
+echo passed.
+
+
+:: Cleanup
+::
+popd
+rd %TESTDIR%
+goto Success
+
+
+:: -----------------------------------------------------------------------------
+:: -- Function section starts below here
+:: -----------------------------------------------------------------------------
+
+::  Failure
+::  - Report test failure
+::
+:Failure
+echo Test failed.
+exit /B 1
+
+::  Success
+::  - Report test success
+::
+:Success
+echo Test succeeded.
+exit /B 0

Added: hadoop/common/branches/branch-1-win/src/winutils/tests/test-winutils-chmod.bat
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1-win/src/winutils/tests/test-winutils-chmod.bat?rev=1378794&view=auto
==============================================================================
--- hadoop/common/branches/branch-1-win/src/winutils/tests/test-winutils-chmod.bat (added)
+++ hadoop/common/branches/branch-1-win/src/winutils/tests/test-winutils-chmod.bat Thu Aug
30 02:34:47 2012
@@ -0,0 +1,174 @@
+:: Licensed to the Apache Software Foundation (ASF) under one or more
+:: contributor license agreements. See the NOTICE file distributed with this
+:: work for additional information regarding copyright ownership. The ASF
+:: licenses this file to you under the Apache License, Version 2.0 (the
+:: "License"); you may not use this file except in compliance with the License.
+:: You may obtain a copy of the License at
+:: 
+:: http://www.apache.org/licenses/LICENSE-2.0
+:: 
+:: Unless required by applicable law or agreed to in writing, software
+:: distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+:: WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+:: License for the specific language governing permissions and limitations under
+:: the License.
+::
+@echo off
+echo Test various chmod operations
+setlocal
+set WINUTILS="%HADOOP_HOME%\bin\winutils.exe"
+set TESTDIR=winutils-test
+
+:: Setup test directory
+::
+if not exist %TESTDIR% md %TESTDIR%
+pushd %TESTDIR%
+
+:: Test cases
+::
+echo Test case 1:
+call:TestChmod "7" "------rwx"
+if %ERRORLEVEL% neq 0 goto Failure
+echo passed.
+
+echo Test case 2:
+call:TestChmod "70" "---rwx---"
+if %ERRORLEVEL% neq 0 goto Failure
+echo passed.
+
+echo Test case 3:
+call:TestChmod "u-x,g+r,o=g" "rw-r--r--"
+if %ERRORLEVEL% neq 0 goto Failure
+echo passed.
+
+echo Test case 4:
+call:TestChmod "u-x,g+rw" "rw-rw----"
+if %ERRORLEVEL% neq 0 goto Failure
+echo passed.
+
+echo Test case 5:
+call:TestChmod "u-x,g+rwx-x,o=u" "rw-rw-rw-"
+if %ERRORLEVEL% neq 0 goto Failure
+echo passed.
+
+echo Test case 6:
+call:TestChmodR "755" "rwxr-xr-x" "rwxr-xr-x"
+if %ERRORLEVEL% neq 0 goto Failure
+echo passed.
+
+echo Test case 7:
+call:TestChmodR "u-x,g+r,o=g" "rw-r--r--" "rw-r--r--"
+if %ERRORLEVEL% neq 0 goto Failure
+echo passed.
+
+echo Test case 8:
+call:TestChmodR "u-x,g+rw" "rw-rw----" "rw-rw----"
+if %ERRORLEVEL% neq 0 goto Failure
+echo passed.
+
+echo Test case 9:
+call:TestChmodR "u-x,g+rwx-x,o=u" "rw-rw-rw-" "rw-rw-rw-"
+if %ERRORLEVEL% neq 0 goto Failure
+echo passed.
+
+echo Test case 10:
+call:TestChmodR "a+rX" "rw-r--r--" "rwxr-xr-x"
+if %ERRORLEVEL% neq 0 goto Failure
+echo passed.
+
+echo Test case 11:
+call:TestChmod "+" "rwx------"
+if %ERRORLEVEL% neq 0 goto Failure
+echo passed.
+
+:: Cleanup
+::
+popd
+rd %TESTDIR%
+goto Success
+
+
+:: -----------------------------------------------------------------------------
+:: -- Function section starts below here
+:: -----------------------------------------------------------------------------
+
+
+::  TestChmod
+::  - Test 'chmod' mode or octal mode string of a single file
+::  - The new permission will be compared with the expected result
+::
+:TestChmod :: [mode|octal mode] [expected permission]
+if exist a exit /B 1
+type NUL>a
+%WINUTILS% chmod 700 a
+%WINUTILS% chmod %~1 a
+call:CmpPerm "a" %~2
+if not %ERRORLEVEL% == 0 exit /B 1
+del a
+exit /B 0
+
+
+::  TestChmodR
+::  - Test 'chmod' mode or octal mode string with recursive option
+::  - The new permission will be compared with the expected results
+::  - The permissions could be different due to 'X' in mode string
+::
+:TestChmodR :: [mode|octal mode] [expected permission] [expected permission x]
+if exist a exit /B 1
+md a
+%WINUTILS% chmod 700 a
+type NUL>a\a
+%WINUTILS% chmod 600 a\a
+md a\b
+%WINUTILS% chmod 700 a\b
+md a\b\a
+%WINUTILS% chmod 700 a\b\a
+type NUL>a\b\b
+%WINUTILS% chmod 600 a\b\b
+type NUL>a\b\x
+%WINUTILS% chmod u+x a\b\x
+
+%WINUTILS% chmod -R %~1 a
+
+call:CmpPerm "a" %~3
+if not %ERRORLEVEL% == 0 exit /B 1
+call:CmpPerm "a\a" %~2
+if not %ERRORLEVEL% == 0 exit /B 1
+call:CmpPerm "a\b" %~3
+if not %ERRORLEVEL% == 0 exit /B 1
+call:CmpPerm "a\b\a" %~3
+if not %ERRORLEVEL% == 0 exit /B 1
+call:CmpPerm "a\b\b" %~2
+if not %ERRORLEVEL% == 0 exit /B 1
+call:CmpPerm "a\b\x" %~3
+if not %ERRORLEVEL% == 0 exit /B 1
+
+rd /S /Q a
+exit /B 0
+
+
+::  CmpPerm
+::  - Compare file permission against given permission
+::  - Use 'ls' to get the new permission
+::  - Exit with errorlevel > 0 on failure
+::
+:CmpPerm :: [file] [perm]
+for /F "tokens=1" %%A in ('call %WINUTILS% ls %~1') do set PERM=%%A
+if not %ERRORLEVEL% == 0 exit /B 1
+if not %PERM:~-9%==%~2 exit /B 1
+exit /B 0 
+
+
+::  Failure
+::  - Report test failure
+::
+:Failure
+echo Test failed.
+exit /B 1
+
+::  Success
+::  - Report test success
+::
+:Success
+echo Test succeeded.
+exit /B 0

Added: hadoop/common/branches/branch-1-win/src/winutils/tests/test-winutils-chown.bat
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1-win/src/winutils/tests/test-winutils-chown.bat?rev=1378794&view=auto
==============================================================================
--- hadoop/common/branches/branch-1-win/src/winutils/tests/test-winutils-chown.bat (added)
+++ hadoop/common/branches/branch-1-win/src/winutils/tests/test-winutils-chown.bat Thu Aug
30 02:34:47 2012
@@ -0,0 +1,95 @@
+:: Licensed to the Apache Software Foundation (ASF) under one or more
+:: contributor license agreements. See the NOTICE file distributed with this
+:: work for additional information regarding copyright ownership. The ASF
+:: licenses this file to you under the Apache License, Version 2.0 (the
+:: "License"); you may not use this file except in compliance with the License.
+:: You may obtain a copy of the License at
+:: 
+:: http://www.apache.org/licenses/LICENSE-2.0
+:: 
+:: Unless required by applicable law or agreed to in writing, software
+:: distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+:: WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+:: License for the specific language governing permissions and limitations under
+:: the License.
+::
+@echo off
+echo Test chown operations
+setlocal
+set WINUTILS="%HADOOP_HOME%\bin\winutils.exe"
+set TESTDIR=winutils-test
+
+:: Setup test directory
+::
+if not exist %TESTDIR% md %TESTDIR%
+pushd %TESTDIR%
+
+:: Get username
+::
+for /F "tokens=1" %%A in ('call whoami') do set USER=%%A
+
+:: Test cases
+::
+echo Test case 1:
+if exist a goto Failure
+type NUL>a
+%WINUTILS% chown %USER%:Administrators a
+if not %ERRORLEVEL% == 0 goto Failure
+call:CmpOwn "a" "%USER%" "BUILTIN\Administrators"
+if not %ERRORLEVEL% == 0 goto Failure
+del a
+if not %ERRORLEVEL% == 0 goto Failure
+echo passed.
+
+echo Test case 2:
+if exist a goto Failure
+type NUL>a
+%WINUTILS% chown %USER% a
+if not %ERRORLEVEL% == 0 goto Failure
+%WINUTILS% chown :Administrators a
+if not %ERRORLEVEL% == 0 goto Failure
+call:CmpOwn "a" "%USER%" "BUILTIN\Administrators"
+if not %ERRORLEVEL% == 0 goto Failure
+del a
+if not %ERRORLEVEL% == 0 goto Failure
+echo passed.
+
+
+:: Cleanup
+::
+popd
+rd %TESTDIR%
+goto Success
+
+:: -----------------------------------------------------------------------------
+:: -- Function section starts below here
+:: -----------------------------------------------------------------------------
+
+::  CmpOwn
+::  - Compare file ownership against expected owner
+::  - Use 'ls' to get the ownership
+::  - Exit with errorlevel > 0 on failure
+::
+:CmpOwn :: [file] [expected user owner] [expected group owner]
+for /F "tokens=3" %%A in ('call %WINUTILS% ls %~1') do set OWNER=%%A
+if not %ERRORLEVEL% == 0 exit /B 1
+for /F "tokens=4" %%A in ('call %WINUTILS% ls %~1') do set GROUP=%%A
+if not %ERRORLEVEL% == 0 exit /B 1
+if /I not %OWNER%==%~2 exit /B 1
+if /I not %GROUP%==%~3 exit /B 1
+exit /B 0 
+
+
+::  Failure
+::  - Report test failure
+::
+:Failure
+echo Test failed.
+exit /B 1
+
+::  Success
+::  - Report test success
+::
+:Success
+echo Test succeeded.
+exit /B 0



Mime
View raw message