1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/multimedia/t_soundmchan.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,289 @@
1.4 +// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// e32test\multimedia\t_soundmchan.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +/**
1.22 + @file Testing access to the shared chunk sound driver from multiple user side threads.
1.23 +*/
1.24 +
1.25 +#include <e32test.h>
1.26 +#include <e32def.h>
1.27 +#include <e32def_private.h>
1.28 +#include "t_soundutils.h"
1.29 +
1.30 +RTest Test(_L("T_SOUNDMCHAN"));
1.31 +
1.32 +const TInt KHeapSize=0x4000;
1.33 +
1.34 +enum TSecThreadTestId
1.35 + {
1.36 + ESecThreadConfigPlayback,
1.37 + ESecThreadConfigRecord,
1.38 + };
1.39 +struct SSecondaryThreadInfo
1.40 + {
1.41 + TSecThreadTestId iTestId;
1.42 +// TInt iExpectedRetVal;
1.43 + TThreadId iThreadId;
1.44 + TInt iDrvHandle;
1.45 + };
1.46 +
1.47 +_LIT(KSndLddFileName,"ESOUNDSC.LDD");
1.48 +_LIT(KSndPddFileName,"SOUNDSC.PDD");
1.49 +
1.50 +
1.51 +LOCAL_C TInt secondaryThread(TAny* aTestInfo)
1.52 + {
1.53 + RTest stest(_L("Secondary test thread"));
1.54 + stest.Title();
1.55 +
1.56 + stest.Start(_L("Check which test to perform"));
1.57 + SSecondaryThreadInfo& sti=*((SSecondaryThreadInfo*)aTestInfo);
1.58 + TInt r;
1.59 + switch(sti.iTestId)
1.60 + {
1.61 + case ESecThreadConfigPlayback:
1.62 + {
1.63 + stest.Next(_L("Duplicate the channel handle passed from main thread"));
1.64 +
1.65 + // Get a reference to the main thread - which created the handle
1.66 + RThread thread;
1.67 + r=thread.Open(sti.iThreadId);
1.68 + stest(r==KErrNone);
1.69 +
1.70 + // Duplicate the driver handle passed from the other thread - for this thread
1.71 + RSoundSc snddev;
1.72 + snddev.SetHandle(sti.iDrvHandle);
1.73 + r=snddev.Duplicate(thread);
1.74 + stest(r==KErrNone);
1.75 + thread.Close();
1.76 +
1.77 + stest.Next(_L("Configure the driver"));
1.78 + // Read the capabilties of this device.
1.79 + TSoundFormatsSupportedV02Buf capsBuf;
1.80 + snddev.Caps(capsBuf);
1.81 + TSoundFormatsSupportedV02& caps=capsBuf();
1.82 +
1.83 + // Read back the default configuration - which must be valid.
1.84 + TCurrentSoundFormatV02Buf formatBuf;
1.85 + snddev.AudioFormat(formatBuf);
1.86 + TCurrentSoundFormatV02& format=formatBuf();
1.87 +
1.88 + if (caps.iEncodings&KSoundEncoding16BitPCM)
1.89 + format.iEncoding = ESoundEncoding16BitPCM;
1.90 + if (caps.iRates&KSoundRate16000Hz)
1.91 + format.iRate = ESoundRate16000Hz;
1.92 + if (caps.iChannels&KSoundStereoChannel)
1.93 + format.iChannels = 2;
1.94 + r=snddev.SetAudioFormat(formatBuf);
1.95 + stest(r==KErrNone);
1.96 + r=snddev.SetVolume(KSoundMaxVolume);
1.97 + stest(r==KErrNone);
1.98 +
1.99 + stest.Next(_L("Close the channel again"));
1.100 + snddev.Close();
1.101 +
1.102 + break;
1.103 + }
1.104 +
1.105 + case ESecThreadConfigRecord:
1.106 + {
1.107 + stest.Next(_L("Use the channel passed from main thread to configure driver"));
1.108 +
1.109 + break;
1.110 + }
1.111 +
1.112 + default:
1.113 + break;
1.114 + }
1.115 +
1.116 +// stest.Getch();
1.117 + stest.End();
1.118 + return(KErrNone);
1.119 + }
1.120 +
1.121 +GLDEF_C TInt E32Main()
1.122 +
1.123 + {
1.124 + __UHEAP_MARK;
1.125 +
1.126 + Test.Title();
1.127 +
1.128 + TInt r;
1.129 + Test.Start(_L("Load sound PDD"));
1.130 + r=User::LoadPhysicalDevice(KSndPddFileName);
1.131 + if (r==KErrNotFound)
1.132 + {
1.133 + Test.Printf(_L("Shared chunk sound driver not supported - test skipped\r\n"));
1.134 + Test.End();
1.135 + Test.Close();
1.136 + __UHEAP_MARKEND;
1.137 + return(KErrNone);
1.138 + }
1.139 + Test(r==KErrNone || r==KErrAlreadyExists);
1.140 +
1.141 + Test.Next(_L("Load sound LDD"));
1.142 + r=User::LoadLogicalDevice(KSndLddFileName);
1.143 + Test(r==KErrNone || r==KErrAlreadyExists);
1.144 +
1.145 + /** @SYMTestCaseID PBASE-T_SOUNDMCHAN-224
1.146 + @SYMTestCaseDesc Opening the channel - more than one channel
1.147 + @SYMTestPriority Critical
1.148 + @SYMTestActions 1) With the LDD and PDD installed and with all channels closed on the device,
1.149 + open a channel for playback on the device.
1.150 + 2) Without closing the first playback channel, attempt to open a second channel
1.151 + for playback on the same device.
1.152 + @SYMTestExpectedResults 1) KErrNone - Channel opens successfully.
1.153 + 2) Should fail with KErrInUse.
1.154 + @SYMREQ PREQ1073.4 */
1.155 +
1.156 + __KHEAP_MARK;
1.157 +
1.158 + Test.Next(_L("Open a channel on the play device"));
1.159 + RSoundSc snddev;
1.160 + r=snddev.Open(KSoundScTxUnit0);
1.161 + Test(r==KErrNone);
1.162 +
1.163 + Test.Next(_L("Try opening the same unit a second time."));
1.164 + RSoundSc snddev2;
1.165 + r=snddev2.Open(KSoundScTxUnit0);
1.166 + Test(r==KErrInUse);
1.167 +
1.168 + Test.Next(_L("Query play formats supported"));
1.169 + TSoundFormatsSupportedV02Buf capsBuf;
1.170 + snddev.Caps(capsBuf);
1.171 + TSoundFormatsSupportedV02& caps=capsBuf();
1.172 + PrintCaps(caps,Test);
1.173 +
1.174 + Test.Next(_L("Try playing without setting the buffer config"));
1.175 + TRequestStatus pStat;
1.176 + snddev.PlayData(pStat,0,0x2000); // 8K
1.177 + User::WaitForRequest(pStat);
1.178 + Test(pStat.Int()==KErrNotReady);
1.179 +
1.180 + Test.Next(_L("Configure the channel from a 2nd thread"));
1.181 + RThread thread;
1.182 + TRequestStatus tStat;
1.183 + SSecondaryThreadInfo sti;
1.184 +
1.185 + sti.iTestId=ESecThreadConfigPlayback;
1.186 + sti.iThreadId=RThread().Id(); // Get the ID of this thread
1.187 + sti.iDrvHandle=snddev.Handle(); // Pass the channel handle
1.188 +
1.189 + /** @SYMTestCaseID PBASE-T_SOUNDMCHAN-225
1.190 + @SYMTestCaseDesc Opening the channel - sharing the handle between threads
1.191 + @SYMTestPriority Critical
1.192 + @SYMTestActions 1) With the LDD and PDD installed and with all channels closed on the device, open a
1.193 + channel for playback on the device. Now create a second thread. Resume this
1.194 + thread - passing the handle to the playback channel to it. Wait for the second
1.195 + thread to terminate.
1.196 + 2) In the second thread, duplicate the playback channel handle.
1.197 + 3) In the second thread, using the duplicated handle, issue a request to set the audio configuration.
1.198 + 4) In the second thread, using the duplicated handle, issue a request to set the volume.
1.199 + 5) In the second thread, close the handle and exit the thread.
1.200 + 6) In the first thread, read back the audio configuration.
1.201 + 7) In the first thread, set the buffer configuration, and then issue a request to play
1.202 + audio data.
1.203 + 8) In the first thread, close the channel.
1.204 + @SYMTestExpectedResults 1) KErrNone - Channel opens successfully.
1.205 + 2) KErrNone - Duplication of the handle succeeds.
1.206 + 3) KErrNone - Audio configured successfully.
1.207 + 4) KErrNone - Volume set successfully.
1.208 + 5) No errors occur closing the channel and exiting the thread.
1.209 + 6) The audio configuration should correspond to that set by the second thread.
1.210 + 7) KErrNone - Setting the buffer configuration and issuing a play request.
1.211 + 8) No errors occur closing the channel.
1.212 + @SYMREQ PREQ1073.4 */
1.213 +
1.214 + r=thread.Create(_L("Thread"),secondaryThread,KDefaultStackSize,KHeapSize,KHeapSize,&sti); // Create secondary thread
1.215 + Test(r==KErrNone);
1.216 + thread.Logon(tStat);
1.217 + thread.Resume();
1.218 + User::WaitForRequest(tStat);
1.219 + Test(tStat.Int()==KErrNone);
1.220 +// Test.Printf(_L("Thread exit info: Cat:%S, Reason:%x, Type:%d\r\n"),&thread.ExitCategory(),thread.ExitReason(),thread.ExitType());
1.221 + Test(thread.ExitType()==EExitKill);
1.222 + thread.Close();
1.223 + User::After(10000); // Wait 10ms
1.224 +
1.225 + Test.Next(_L("Read back the play configuration"));
1.226 + TCurrentSoundFormatV02Buf formatBuf;
1.227 + snddev.AudioFormat(formatBuf);
1.228 + TCurrentSoundFormatV02& format=formatBuf();
1.229 + PrintConfig(format,Test);
1.230 +
1.231 + Test.Next(_L("Set the buffer configuration"));
1.232 + RChunk chunk;
1.233 + TInt bufSize=BytesPerSecond(formatBuf()); // Large enough to hold 1 second of data.
1.234 + bufSize=ValidBufferSize(bufSize,caps.iRequestMinSize,formatBuf()); // Keep the buffer length valid for driver.
1.235 + TTestSharedChunkBufConfig bufferConfig;
1.236 + bufferConfig.iNumBuffers=1;
1.237 + bufferConfig.iBufferSizeInBytes=bufSize;
1.238 + bufferConfig.iFlags=0;
1.239 + TPckg<TTestSharedChunkBufConfig> bufferConfigBuf(bufferConfig);
1.240 + r=snddev.SetBufferChunkCreate(bufferConfigBuf,chunk);
1.241 + Test(r==KErrNone);
1.242 + snddev.GetBufferConfig(bufferConfigBuf);
1.243 + PrintBufferConf(bufferConfig,Test);
1.244 + Test(bufferConfig.iBufferSizeInBytes==bufSize);
1.245 +
1.246 + Test.Next(_L("Start playing"));
1.247 + r=MakeSineTable(format);
1.248 + Test(r==KErrNone);
1.249 + r=SetToneFrequency(660,format);
1.250 + Test(r==KErrNone);
1.251 + TPtr8 ptr(chunk.Base()+bufferConfig.iBufferOffsetList[0],bufSize);
1.252 + WriteTone(ptr,format);
1.253 + snddev.PlayData(pStat,bufferConfig.iBufferOffsetList[0],bufSize,KSndFlagLastSample);
1.254 + User::WaitForRequest(pStat);
1.255 + Test(tStat.Int()==KErrNone);
1.256 +
1.257 + Test.Next(_L("Close the drivers and the chunk"));
1.258 + chunk.Close();
1.259 + snddev.Close();
1.260 +
1.261 + __KHEAP_MARKEND;
1.262 +
1.263 + Test.Next(_L("Unload the drivers"));
1.264 +
1.265 + r=User::FreeLogicalDevice(KDevSoundScName);
1.266 + Test.Printf(_L("Unloading %S.LDD - %d\r\n"),&KDevSoundScName,r);
1.267 + Test(r==KErrNone);
1.268 +
1.269 + TName pddName(KDevSoundScName);
1.270 + _LIT(KPddWildcardExtension,".*");
1.271 + pddName.Append(KPddWildcardExtension);
1.272 + TFindPhysicalDevice findPD(pddName);
1.273 + TFullName findResult;
1.274 + r=findPD.Next(findResult);
1.275 + while (r==KErrNone)
1.276 + {
1.277 + r=User::FreePhysicalDevice(findResult);
1.278 + Test.Printf(_L("Unloading %S.PDD - %d\r\n"),&findResult,r);
1.279 + Test(r==KErrNone);
1.280 + findPD.Find(pddName); // Reset the find handle now that we have deleted something from the container.
1.281 + r=findPD.Next(findResult);
1.282 + }
1.283 +
1.284 + Test.End();
1.285 + Test.Close();
1.286 +
1.287 + Cleanup();
1.288 +
1.289 + __UHEAP_MARKEND;
1.290 +
1.291 + return(KErrNone);
1.292 + }