none
Creating Package from Content Levels RRS feed

  • Question

  • Hi,

    I am trying to run hck tests with the help of APIs.

    now am able to run tests based on content levels. but am unable to create package once execution is completed.

    everything happens fine except package creation.  

    below is the code

     List<ContentLevelType> contentLevelTypes = new List<ContentLevelType>
                                                               {
                                                                   ContentLevelType.Basic,
                                                                   ContentLevelType.Functional,
                                                                   ContentLevelType.Reliability,
                                                                   ContentLevelType.Certification,
                                                                   ContentLevelType.Experiences,
                                                                   ContentLevelType.Optional
                                                               };


                tests = project.GetTests(contentLevelTypes);

    tests = project.GetTests(new[] { ContentLevelType.Optional });

    foreach (Test test in tests)
               {
                   bool automatedTest = test.TestType == TestType.Automated;

                    if (automatedTest)
                    {
                       test.QueueTest();

                   }

    }

                                            

       foreach (Machine machine in testPool.GetMachines())
                        {
                         if (machine.Status == MachineStatus.Running)
                            { 

    //Wait till the execution completes

    }

    else

    {

    project = manager.GetProject(projectName);

                        PackageWriter package_Write = new PackageWriter(project);

                    

    package_Write.Save(filename); //save it
        package_Write.Dispose();

    }


    Tuesday, August 27, 2013 9:34 AM

All replies

  • Can you be more specific? Is there an exception thrown? Another issue is that the code snippet above is missing some syntax - are you really trying to create a package for each machine in the machine pool?

    John -- This posting is provided "AS IS" with no warranties, and confers no rights.

    Tuesday, August 27, 2013 4:35 PM
  • Am getting the following exception during package creation. it happens only sometimes. sometimes, package gets created successfully. i guess this happens, if more tests are queued for execution. 

    Unhandled Exception: Microsoft.Windows.Kits.Hardware.ObjectModel.ScheduleException: Could not query for result Id: 13754 at Microsoft.Windows.Kits.Hardware.ObjectModel.DBConnection.WttTestResult.Refresh()

    at Microsoft.Windows.Kits.Hardware.ObjectModel.Submission.PackageTestResult..ctor(TestResult testResult)

    at Microsoft.Windows.Kits.Hardware.ObjectModel.Submission.SerializationVisitor.Microsoft.Windows.Kits.Hardware .ObjectModel.Submission.IPackageVisitor.VisitTestResult(TestResult result, Int32 testId)   at Microsoft.Windows.Kits.Hardware.ObjectModel.Submission.SerializationVisitor.Microsoft.Windows.Kits.Hardware.ObjectModel.Submission.IPackageVisitor.VisitTest(Test test, Int32 targetId)   at Microsoft.Windows.Kits.Hardware.ObjectModel.Submission.SerializationVisitor.Microsoft.Windows.Kits.Hardware.ObjectModel.Submission.IPackageVisitor.VisitTarget(Target target,Int32 targetFamilyId, Boolean isDeepMerged)   at Microsoft.Windows.Kits.Hardware.ObjectModel.Submission.SerializationVisitor.Microsoft.Windows.Kits.Hardware.ObjectModel.Submission.IPackageVisitor.VisitTargetFamily(TargetFamily targetFamily, Int32 productInstanceId)   at Microsoft.Windows.Kits.Hardware.ObjectModel.Submission.SerializationVisitor.Microsoft.Windows.Kits.Hardware.ObjectModel.Submission.IPackageVisitor.VisitProductInstance(ProductInstance productInstance, Int32 projectId)   at Microsoft.Windows.Kits.Hardware.ObjectModel.Submission.SerializationVisitor.Microsoft.Windows.Kits.Hardware.ObjectModel.Submission.IPackageVisitor.VisitProject(Project project, List`1 driverList)   at Microsoft.Windows.Kits.Hardware.ObjectModel.Submission.PackageWriter.Save(String packageFile)   at Samples.HelloWorld.Main(String[] args) in c:\Users\Projects\with-contentlevels\with-contentlevels\Program.cs:line 186

    Code attached below.

    namespace Samples
    {
        using System;
        using System.Collections.Generic;
        using System.ComponentModel;
        using System.Data;
        using System.Drawing;
        using System.Linq;
        using System.Text;
        using System.Threading.Tasks;
    
        using System.Threading;
        using Microsoft.Windows.Kits.Hardware.ObjectModel;
        using Microsoft.Windows.Kits.Hardware.ObjectModel.DBConnection;
        using Microsoft.Windows.Kits.Hardware.ObjectModel.Submission;
        using System.Collections.Specialized;
        using System.Collections.ObjectModel;
        using System.IO;
        using Microsoft.Windows.Kits.Hardware.Logging;
        using Microsoft.Windows.Kits.Hardware.FilterEngine;
    
    
        public class HelloWorld
        {
            public static void Main(string[] args)
            {
                string projectName = "my new project";
    
                string operatingSystemType = "Windows v6.3 x86";
                string controllerName = @" ";
                MachinePool testPool;
    
                ProjectManager manager = new DatabaseProjectManager(controllerName);
                Console.WriteLine("Connected to server  : {0}", controllerName);
                MachinePool rootPool = manager.GetRootMachinePool();
    
                testPool = manager.GetRootMachinePool().GetChildPools().Where(x => x.Name == "TestPool").FirstOrDefault();
                if (testPool == null)
                {
                    testPool = manager.GetRootMachinePool().CreateChildPool("TestPool");
                }
    
                foreach (Machine machine in rootPool.DefaultPool.GetMachines().Where(x => x.OSPlatform.Description == operatingSystemType))
                {
                    // each of these computers is then moved into the test pool
                    rootPool.DefaultPool.MoveMachineTo(machine, testPool);
                }
    
                foreach (Machine machine in testPool.GetMachines())
                {
                    machine.SetMachineStatus(MachineStatus.Ready, -1);
                }
                Console.WriteLine("Machine is in Ready state");
                //---------------
                // creating a project
                //---------------
                Project project = manager.CreateProject(projectName);
    
                OSPlatform platform = testPool.GetMachines().First().OSPlatform;
                ProductInstance pi = project.CreateProductInstance(platform.Name, testPool, platform);
    
                Console.WriteLine("Created Project: {0} ", projectName);
    
                ReadOnlyCollection<TargetData> data = pi.FindTargetFromSystem();
    
                pi.CreateTarget(data.First());
    
                List<ContentLevelType> contentLevelTypes = new List<ContentLevelType>
                                                               {
                                                                   ContentLevelType.Basic,
                                                                   ContentLevelType.Functional,
                                                                   ContentLevelType.Reliability,
                                                                   ContentLevelType.Certification,
                                                                   ContentLevelType.Experiences,
                                                                   ContentLevelType.Optional
                                                               };
    
                
               
                List<Test> tests = project.GetTests(contentLevelTypes).Where(test => test.TestType == TestType.Automated && !test.ScheduleOptions.HasFlag(DistributionOption.RequiresMultipleMachines) && !test.RequiresSpecialConfiguration && !test.RequiresSupplementalContent).ToList();
                int originalTestCount = tests.Count;
                
                Console.WriteLine("Total no of tests are : {0}", originalTestCount);
                
                foreach (Test test in tests)
                {
                   Console.WriteLine("Scheduling, {0} :", test.Name);
                    test.QueueTest();
                }
    
                while (project.Info.Status == ProjectStatus.Running)
                {
                    // sleep for 1 minute
                    Thread.Sleep(60 * 1000);
                }
               
                ReadOnlyCollection<ContentLevelRollupInfo> rollupSummaryByContentLevels = project.Info.RollupSummaryByContentLevels;
    
                Console.Out.WriteLine("Roll-up summary by content level for project: '{0}'", projectName);
                foreach (ContentLevelRollupInfo rollupInfo in rollupSummaryByContentLevels)
                {
                    Console.Out.WriteLine("\tSummary for '{0}' level:", rollupInfo.ContentLevel);
                    Console.Out.WriteLine("\t\tFailedCount: {0}", rollupInfo.FailedCount);
                    Console.Out.WriteLine("\t\tNotRunCount: {0}", rollupInfo.NotRunCount);
                    Console.Out.WriteLine("\t\tPassedCount: {0}", rollupInfo.PassedCount);
                    Console.Out.WriteLine("\t\tRunningCount: {0}", rollupInfo.RunningCount);
                    Console.Out.WriteLine("\t\tTotalCount: {0}", rollupInfo.TotalCount);
                    Console.Out.WriteLine("\t\tStatus: {0}", rollupInfo.Status);
                }
                Console.WriteLine("Execution is done. Creating Package");
                
                
                string result = "  ";
                string projfinalpath = "  "; //path
    
                Directory.SetCurrentDirectory(projfinalpath);
    
                Microsoft.Windows.Kits.Hardware.ObjectModel.Submission.PackageWriter package = new PackageWriter(project);
              package.SetProgressActionHandler(SubmissionCreationProgressHandler);
    
                Console.WriteLine("Package path is : {0}", projfinalpath);
                package.Save(result);
                package.Dispose();
                
            }
            public static void SubmissionCreationProgressHandler(PackageProgressInfo info)
            {
                Console.WriteLine("Package progress {0} of {1} : {2}", info.Current, info.Maximum, info.Message);
            }
    
        }
    }
    

    Thursday, August 29, 2013 7:28 AM
  • This could be a timing issue, if you scheduled new tests or tests are getting scheduled during package creation. It could also be an issue if you've deleted results. I've noted this issue to see if we can repro this internally. Recommendation is to make sure tests are not running when packaging.


    John -- This posting is provided "AS IS" with no warranties, and confers no rights.

    Thursday, August 29, 2013 4:38 PM
  • you are probably getting an issue because you are excluding manual tests. I believe a package can only be created if all the tests under the contenleveltype certification have been executed. 
    Wednesday, January 6, 2016 8:11 PM