SlideShare uma empresa Scribd logo
1 de 35
Baixar para ler offline
Testing Apache Modules with Python
and ctypes
ApacheCon US 2009

Markus Litz   - 06.11.2009


                                                           Slide 1
                              Standard presentation deck > Sep. 2009
Agenda for today

  Why?


  Introduction to ctypes


  Preparing the apache


  Creating tests


  Demo

                                                        Slide 2
                           Standard presentation deck > Sep. 2009
DLR
German Aerospace Center




   Research Institution
   Research Areas
      Aeronautics
      Space
      Transport
      Energy
   Space Agency



                                                       Slide 3
                          Standard presentation deck > Sep. 2009
Locations and employees

6200 employees across                 Hamburg 
29 research institutes and                                          Neustrelitz
                                  Bremen        Trauen
facilities at
                                                           Berlin 
         13 sites.                 Braunschweig 

                                    Dortmund  Goettingen
Offices in Brussels,
                                  Koeln
Paris and Washington.             Bonn


                             Lampoldshausen 

                                  Stuttgart 

                                                      Oberpfaffenhofen
                                           Weilheim 




                                                                                        Slide 4
                                                           Standard presentation deck > Sep. 2009
Background

 DataFinder – a application for scientific data management
     Storing and managing huge amounts of data
     Search through the resource content and metadata
     Various ways to store data, for example
          ftp, network share, offline stores
     Metadata management with the WebDAV protocol
          Two supported WebDAV Server:
                Tamino XML Server & Catacomb




                                                                             Slide 5
                                                Standard presentation deck > Sep. 2009
Catacomb – A WebDAV Server Module for
Apache




                                                           Slide 6
                              Standard presentation deck > Sep. 2009
Catacomb – The Difference to mod_dav_fs

    Saving the resources
        mod_dav_fs save content and properties in files on
       the filesystem
        mod_dav_fs creates for every resource, and also for
       every collection, their own property file

    Consequence:
       A single query of server side searching needs to open
       many files
       Implementation of complex queries is difficult
       Full text search is expensive

                                                                               Slide 7
                                                  Standard presentation deck > Sep. 2009
Catacomb – A WebDAV Server Module for
Apache
  WebDAV repository module for mod_dav

  Catacomb uses relational databases to store the metadata
      Strong search performance through SQL statements

  Catacomb is:
      Good for Content management
      Good for Collaborated web authoring
          Support locks, avoid the “lost update” problem
      Capable of searching (DASL) and versioning (DeltaV)
     resources
                                                                               Slide 8
                                                  Standard presentation deck > Sep. 2009
Catacomb – History and Current State

   Initial development at the University of California under the
  chair of Jim Whitehead

   Open Source project since 2002

   DeltaV and DASL implementation

   Since 2006 contribution of the DLR
       ACP support
       Database abstraction using mod_dbd
       License changed to ASL2.0
                                                                                 Slide 9
                                                    Standard presentation deck > Sep. 2009
Why testing your code?

  Development is faster and easier


  Code is more robust


  Code is more maintainable


  Code is more reliable




                                                                Slide 10
                                     Standard presentation deck > Sep. 2009
Why testing with Python and ctypes?

  Writing tests is easy


  No need to start an apache instance every time


  Tests could be automatically done with various
 Apache versions




                                                                        Slide 11
                                             Standard presentation deck > Sep. 2009
What is ctypes

  ctypes is a wrapper for C-librarys for python


  ctypes allows to call functions in dlls/shared libraries
 from python code


  It is possible to implement C callback function


  Since Python 2.5.x, ctypes is in the standard library



                                                                             Slide 12
                                                  Standard presentation deck > Sep. 2009
How to use ctypes

  from ctypes import *


  Loading dynamic link libraries
     libc = cdll.msvcr
     libc = CDLL("libc.so.6")


  Calling functions
     print libc.time(None)


                                                              Slide 13
                                   Standard presentation deck > Sep. 2009
Fundamental data types

  Good support for many primitive C compatible data
 types:


      C                 Python
     char              c_char
     int               c_int
     long              c_long
     void*             c_void_p



                                                                       Slide 14
                                            Standard presentation deck > Sep. 2009
Fundamental data types - usage

All these types can be created by calling them with an optional initializer
of the correct type and value:

    i = c_int(42)
    print i.value             # „42“
    i.value = -1
    print i.value             # „-1“


    num = c_double(3.14)
    libc.printf("Number: %fn“, num)
                                               # „Numner: 3.14“

                                                                                      Slide 15
                                                           Standard presentation deck > Sep. 2009
Using pointers

  byref() passes parameters by reference
     libc.sscanf("1 3.14 Hello", "%d %f
               %s", byref(i), byref(f), s)


  Creating a pointer
   i = c_int(42)
   pi = pointer(i)




                                                             Slide 16
                                  Standard presentation deck > Sep. 2009
Return types

  Default return type: int

  strcat = libc.strcat
  strcat("abc", "def"))       # „8059983“


  strcat.restype = c_char_p
  strcat("abc", "def"))       # „abcdef“




                                                              Slide 17
                                   Standard presentation deck > Sep. 2009
Arrays
  Create an array-type
     TenIntsArrayType = c_int * 10


  Create an array-instance
     array1 = TenIntegers()
     array2 = TenIntegers(1, 2, 3, 4, 5, 6,
    7, 8, 9, 10)


  Using arrays
     Array1[3]           “0”
     Array2[3]           “4”

                                                                Slide 18
                                     Standard presentation deck > Sep. 2009
Structures and unions


  class POINT(Structure):
     _fields_ = [("x", c_int),
                 ("y", c_int)]

  point = POINT(10, 20)
  print point.x, point.y            „10 20“




                                                                Slide 19
                                     Standard presentation deck > Sep. 2009
UnitTesting Apache Modules

  The problem
      (Most) functions of a module could only be tested with
     a running apache
      Module-functions could not be called directly

  The solutions
      Starting and stopping an apache on each test
      Test functions from the module directly using ctypes




                                                                            Slide 20
                                                 Standard presentation deck > Sep. 2009
Calling module functions directly

  Causes a exception stops execution
     On runtime, ctypes tries to resolve all dynamic
    symbols
      All apache specific methods and data structures
     are not available


  Solution:
      Building Apache as a shared core



                                                                        Slide 21
                                             Standard presentation deck > Sep. 2009
Building-kernel apache as a share core

  Building the apache kernel as shared module
     On apache 1.x
         --enable-rule=SHARED_CORE


    On apache 2.x build infrastructure doesn't seem to
   know this anymore




                                                                       Slide 22
                                            Standard presentation deck > Sep. 2009
Compiling Apache

  Compiling apache

    make clean
    CFLAGS='-D SHARED_CORE -fPIC '
   ./configure
    make




                                                            Slide 23
                                 Standard presentation deck > Sep. 2009
Linking the Shared Core

  After compiling, the make command links apache
      libtool ... -mode=link gcc ... -o httpd
    ..


  Linking command for a shared core
      libtool ... -mode=link gcc ...
    -shared -o libhttpd.so ..server/exports.o




                                                                   Slide 24
                                        Standard presentation deck > Sep. 2009
Modifications of the Module

  Module must be linked against the shared core

     LDFLAGS = -lhttpd -L </…/libhttpd.so>


     Could be an extra make-target




                                                                      Slide 25
                                           Standard presentation deck > Sep. 2009
Apache Data Structures in Python

class apr_allocator_t(Structure):

class apr_memnode_t(Structure):

class apr_pool_t(Structure):

class cleanup_t(Structure):




                                                               Slide 26
                                    Standard presentation deck > Sep. 2009
Setting Up Data Structures – apt_pool_t
class apr_pool_t(Structure):
    _fields_ = [("cleanups",POINTER(cleanup_t)),
                ("free_cleanups",POINTER(cleanup_t)),
                ("allocator",POINTER(apr_allocator_t)),
                ("subprocesses",POINTER(process_chain)),
                ("abort_fn",c_void_p),
                ("user_data",c_void_p),
                ("tag",c_char_p),
                ("active",POINTER(apr_memnode_t)),
                ("self",POINTER(apr_memnode_t)),
                ("self_first_avail",c_char_p),
                ("parent",POINTER(apr_pool_t)),
                ("child",POINTER(apr_pool_t)),
                ("sibling",POINTER(apr_pool_t)),
                ("ref",POINTER(POINTER(apr_pool_t)))]
                                                                          Slide 27
                                               Standard presentation deck > Sep. 2009
Setting Up Data Structures – GCC

  Ctypes code generator – modified version of GCC

  Looks for declarations in C header files. Generates python
 codes for:
      enums, structs, unions, function declarations, com
    interfaces, and preprocessor definitions

  Very early stage




                                                                            Slide 28
                                                 Standard presentation deck > Sep. 2009
Unit Test Framwork (nose)

  Simple structure, one class for each testing object

     Setup_class()
     Test1()
     …
     TestX()
     TearDown_class()




                                                                              Slide 29
                                                   Standard presentation deck > Sep. 2009
Setting up the Test Environment
def setup (self) :
    self.catacomb = CDLL("/apachecon/libmod_dav_repos.so")
    self.httpd = CDLL("/apachecon/libhttpd.so")
    self.apr = CDLL("/apachecon/lib/libapr-1.so")


    self.pool = c_void_p()
    self.allocator = c_void_p()


    self.apr.apr_initialize()
    self.apr.apr_allocator_create(byref(self.allocator))
    self.apr.apr_pool_create_ex(byref(self.pool), None,
                                   None, self.allocator)




                                                                              Slide 30
                                                   Standard presentation deck > Sep. 2009
Writing the Test

def testSomething(self):
   assert self.catacomb.function_to_test(arg1,
                     byref(arg2)) == “true”




                                                                       Slide 31
                                            Standard presentation deck > Sep. 2009
Shutting down the Test Environment


def teardown(self):
    self.apr.apr_pool_destroy(self.pool)
    self.apr.apr_allocator_destroy(self.allocator)
    self.apr.apr_terminate()




                                                                   Slide 32
                                        Standard presentation deck > Sep. 2009
Summary of Steps

  Compile Apache as a shared core


  Link own module against shared core


  Define the data structures you need


  Write the tests


  Run the test

                                                                   Slide 33
                                        Standard presentation deck > Sep. 2009
Conclusion

  Powerful possibility to create tests with no need of a
 running Apache.
   Tests could be made in an easy language with
 possibility to easily make moc-objects.
   Writing a test is in most cases less than writing 10
 lines of code.
  Tests are easily portable to other systems/apache-
 versions.




                                                                           Slide 34
                                                Standard presentation deck > Sep. 2009
Demonstration

  Before the demo:


     Thanks to Steven Mohr




                                                        Slide 35
                             Standard presentation deck > Sep. 2009

Mais conteúdo relacionado

Semelhante a Testing Apache Modules with Python and Ctypes

9. oo languages
9. oo languages9. oo languages
9. oo languages
APU
 
9.oo languages
9.oo languages9.oo languages
9.oo languages
APU
 
Intro to c# (vs. objective c and java)
Intro to c# (vs. objective c and java)Intro to c# (vs. objective c and java)
Intro to c# (vs. objective c and java)
John Smith
 
Intro to c# (vs. objective c and java)
Intro to c# (vs. objective c and java)Intro to c# (vs. objective c and java)
Intro to c# (vs. objective c and java)
Wes Yanaga
 
Legacy of Void*
Legacy of Void*Legacy of Void*
Legacy of Void*
Adam Crain
 
tybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notestybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notes
WE-IT TUTORIALS
 

Semelhante a Testing Apache Modules with Python and Ctypes (20)

02 c++g3 d
02 c++g3 d02 c++g3 d
02 c++g3 d
 
T2
T2T2
T2
 
Framework engineering JCO 2011
Framework engineering JCO 2011Framework engineering JCO 2011
Framework engineering JCO 2011
 
Bounded Model Checking for C Programs in an Enterprise Environment
Bounded Model Checking for C Programs in an Enterprise EnvironmentBounded Model Checking for C Programs in an Enterprise Environment
Bounded Model Checking for C Programs in an Enterprise Environment
 
C# tutorial
C# tutorialC# tutorial
C# tutorial
 
9. oo languages
9. oo languages9. oo languages
9. oo languages
 
9.oo languages
9.oo languages9.oo languages
9.oo languages
 
Hybrid Cloud, Kubeflow and Tensorflow Extended [TFX]
Hybrid Cloud, Kubeflow and Tensorflow Extended [TFX]Hybrid Cloud, Kubeflow and Tensorflow Extended [TFX]
Hybrid Cloud, Kubeflow and Tensorflow Extended [TFX]
 
Intro to c# (vs. objective c and java)
Intro to c# (vs. objective c and java)Intro to c# (vs. objective c and java)
Intro to c# (vs. objective c and java)
 
Intro to c# (vs. objective c and java)
Intro to c# (vs. objective c and java)Intro to c# (vs. objective c and java)
Intro to c# (vs. objective c and java)
 
Legacy of Void*
Legacy of Void*Legacy of Void*
Legacy of Void*
 
Srgoc dotnet_new
Srgoc dotnet_newSrgoc dotnet_new
Srgoc dotnet_new
 
tybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notestybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notes
 
Lotusphere 2007 AD505 DevBlast 30 LotusScript Tips
Lotusphere 2007 AD505 DevBlast 30 LotusScript TipsLotusphere 2007 AD505 DevBlast 30 LotusScript Tips
Lotusphere 2007 AD505 DevBlast 30 LotusScript Tips
 
High Quality Symfony Bundles tutorial - Dutch PHP Conference 2014
High Quality Symfony Bundles tutorial - Dutch PHP Conference 2014High Quality Symfony Bundles tutorial - Dutch PHP Conference 2014
High Quality Symfony Bundles tutorial - Dutch PHP Conference 2014
 
Introduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdfIntroduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdf
 
Visual studio.net
Visual studio.netVisual studio.net
Visual studio.net
 
Advance Android Application Development
Advance Android Application DevelopmentAdvance Android Application Development
Advance Android Application Development
 
Mac ruby deployment
Mac ruby deploymentMac ruby deployment
Mac ruby deployment
 
Writing a Gem with native extensions
Writing a Gem with native extensionsWriting a Gem with native extensions
Writing a Gem with native extensions
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Último (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 

Testing Apache Modules with Python and Ctypes

  • 1. Testing Apache Modules with Python and ctypes ApacheCon US 2009 Markus Litz - 06.11.2009 Slide 1 Standard presentation deck > Sep. 2009
  • 2. Agenda for today Why? Introduction to ctypes Preparing the apache Creating tests Demo Slide 2 Standard presentation deck > Sep. 2009
  • 3. DLR German Aerospace Center Research Institution Research Areas Aeronautics Space Transport Energy Space Agency Slide 3 Standard presentation deck > Sep. 2009
  • 4. Locations and employees 6200 employees across Hamburg  29 research institutes and  Neustrelitz Bremen   Trauen facilities at Berlin   13 sites. Braunschweig   Dortmund  Goettingen Offices in Brussels,  Koeln Paris and Washington.  Bonn Lampoldshausen  Stuttgart   Oberpfaffenhofen Weilheim  Slide 4 Standard presentation deck > Sep. 2009
  • 5. Background DataFinder – a application for scientific data management Storing and managing huge amounts of data Search through the resource content and metadata Various ways to store data, for example ftp, network share, offline stores Metadata management with the WebDAV protocol Two supported WebDAV Server: Tamino XML Server & Catacomb Slide 5 Standard presentation deck > Sep. 2009
  • 6. Catacomb – A WebDAV Server Module for Apache Slide 6 Standard presentation deck > Sep. 2009
  • 7. Catacomb – The Difference to mod_dav_fs Saving the resources mod_dav_fs save content and properties in files on the filesystem mod_dav_fs creates for every resource, and also for every collection, their own property file Consequence: A single query of server side searching needs to open many files Implementation of complex queries is difficult Full text search is expensive Slide 7 Standard presentation deck > Sep. 2009
  • 8. Catacomb – A WebDAV Server Module for Apache WebDAV repository module for mod_dav Catacomb uses relational databases to store the metadata Strong search performance through SQL statements Catacomb is: Good for Content management Good for Collaborated web authoring Support locks, avoid the “lost update” problem Capable of searching (DASL) and versioning (DeltaV) resources Slide 8 Standard presentation deck > Sep. 2009
  • 9. Catacomb – History and Current State Initial development at the University of California under the chair of Jim Whitehead Open Source project since 2002 DeltaV and DASL implementation Since 2006 contribution of the DLR ACP support Database abstraction using mod_dbd License changed to ASL2.0 Slide 9 Standard presentation deck > Sep. 2009
  • 10. Why testing your code? Development is faster and easier Code is more robust Code is more maintainable Code is more reliable Slide 10 Standard presentation deck > Sep. 2009
  • 11. Why testing with Python and ctypes? Writing tests is easy No need to start an apache instance every time Tests could be automatically done with various Apache versions Slide 11 Standard presentation deck > Sep. 2009
  • 12. What is ctypes ctypes is a wrapper for C-librarys for python ctypes allows to call functions in dlls/shared libraries from python code It is possible to implement C callback function Since Python 2.5.x, ctypes is in the standard library Slide 12 Standard presentation deck > Sep. 2009
  • 13. How to use ctypes from ctypes import * Loading dynamic link libraries libc = cdll.msvcr libc = CDLL("libc.so.6") Calling functions print libc.time(None) Slide 13 Standard presentation deck > Sep. 2009
  • 14. Fundamental data types Good support for many primitive C compatible data types: C Python char  c_char int  c_int long  c_long void*  c_void_p Slide 14 Standard presentation deck > Sep. 2009
  • 15. Fundamental data types - usage All these types can be created by calling them with an optional initializer of the correct type and value: i = c_int(42) print i.value # „42“ i.value = -1 print i.value # „-1“ num = c_double(3.14) libc.printf("Number: %fn“, num) # „Numner: 3.14“ Slide 15 Standard presentation deck > Sep. 2009
  • 16. Using pointers byref() passes parameters by reference libc.sscanf("1 3.14 Hello", "%d %f %s", byref(i), byref(f), s) Creating a pointer i = c_int(42) pi = pointer(i) Slide 16 Standard presentation deck > Sep. 2009
  • 17. Return types Default return type: int strcat = libc.strcat strcat("abc", "def")) # „8059983“ strcat.restype = c_char_p strcat("abc", "def")) # „abcdef“ Slide 17 Standard presentation deck > Sep. 2009
  • 18. Arrays Create an array-type TenIntsArrayType = c_int * 10 Create an array-instance array1 = TenIntegers() array2 = TenIntegers(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) Using arrays Array1[3]  “0” Array2[3]  “4” Slide 18 Standard presentation deck > Sep. 2009
  • 19. Structures and unions class POINT(Structure): _fields_ = [("x", c_int), ("y", c_int)] point = POINT(10, 20) print point.x, point.y  „10 20“ Slide 19 Standard presentation deck > Sep. 2009
  • 20. UnitTesting Apache Modules The problem (Most) functions of a module could only be tested with a running apache Module-functions could not be called directly The solutions Starting and stopping an apache on each test Test functions from the module directly using ctypes Slide 20 Standard presentation deck > Sep. 2009
  • 21. Calling module functions directly Causes a exception stops execution On runtime, ctypes tries to resolve all dynamic symbols All apache specific methods and data structures are not available Solution: Building Apache as a shared core Slide 21 Standard presentation deck > Sep. 2009
  • 22. Building-kernel apache as a share core Building the apache kernel as shared module On apache 1.x --enable-rule=SHARED_CORE On apache 2.x build infrastructure doesn't seem to know this anymore Slide 22 Standard presentation deck > Sep. 2009
  • 23. Compiling Apache Compiling apache make clean CFLAGS='-D SHARED_CORE -fPIC ' ./configure make Slide 23 Standard presentation deck > Sep. 2009
  • 24. Linking the Shared Core After compiling, the make command links apache libtool ... -mode=link gcc ... -o httpd .. Linking command for a shared core libtool ... -mode=link gcc ... -shared -o libhttpd.so ..server/exports.o Slide 24 Standard presentation deck > Sep. 2009
  • 25. Modifications of the Module Module must be linked against the shared core LDFLAGS = -lhttpd -L </…/libhttpd.so> Could be an extra make-target Slide 25 Standard presentation deck > Sep. 2009
  • 26. Apache Data Structures in Python class apr_allocator_t(Structure): class apr_memnode_t(Structure): class apr_pool_t(Structure): class cleanup_t(Structure): Slide 26 Standard presentation deck > Sep. 2009
  • 27. Setting Up Data Structures – apt_pool_t class apr_pool_t(Structure): _fields_ = [("cleanups",POINTER(cleanup_t)), ("free_cleanups",POINTER(cleanup_t)), ("allocator",POINTER(apr_allocator_t)), ("subprocesses",POINTER(process_chain)), ("abort_fn",c_void_p), ("user_data",c_void_p), ("tag",c_char_p), ("active",POINTER(apr_memnode_t)), ("self",POINTER(apr_memnode_t)), ("self_first_avail",c_char_p), ("parent",POINTER(apr_pool_t)), ("child",POINTER(apr_pool_t)), ("sibling",POINTER(apr_pool_t)), ("ref",POINTER(POINTER(apr_pool_t)))] Slide 27 Standard presentation deck > Sep. 2009
  • 28. Setting Up Data Structures – GCC Ctypes code generator – modified version of GCC Looks for declarations in C header files. Generates python codes for: enums, structs, unions, function declarations, com interfaces, and preprocessor definitions Very early stage Slide 28 Standard presentation deck > Sep. 2009
  • 29. Unit Test Framwork (nose) Simple structure, one class for each testing object Setup_class() Test1() … TestX() TearDown_class() Slide 29 Standard presentation deck > Sep. 2009
  • 30. Setting up the Test Environment def setup (self) : self.catacomb = CDLL("/apachecon/libmod_dav_repos.so") self.httpd = CDLL("/apachecon/libhttpd.so") self.apr = CDLL("/apachecon/lib/libapr-1.so") self.pool = c_void_p() self.allocator = c_void_p() self.apr.apr_initialize() self.apr.apr_allocator_create(byref(self.allocator)) self.apr.apr_pool_create_ex(byref(self.pool), None, None, self.allocator) Slide 30 Standard presentation deck > Sep. 2009
  • 31. Writing the Test def testSomething(self): assert self.catacomb.function_to_test(arg1, byref(arg2)) == “true” Slide 31 Standard presentation deck > Sep. 2009
  • 32. Shutting down the Test Environment def teardown(self): self.apr.apr_pool_destroy(self.pool) self.apr.apr_allocator_destroy(self.allocator) self.apr.apr_terminate() Slide 32 Standard presentation deck > Sep. 2009
  • 33. Summary of Steps Compile Apache as a shared core Link own module against shared core Define the data structures you need Write the tests Run the test Slide 33 Standard presentation deck > Sep. 2009
  • 34. Conclusion Powerful possibility to create tests with no need of a running Apache. Tests could be made in an easy language with possibility to easily make moc-objects. Writing a test is in most cases less than writing 10 lines of code. Tests are easily portable to other systems/apache- versions. Slide 34 Standard presentation deck > Sep. 2009
  • 35. Demonstration Before the demo: Thanks to Steven Mohr Slide 35 Standard presentation deck > Sep. 2009